I store user different data in the user_data table, and when I get this data with the association definition that I defined, and then I actually cache it using a Ruby instance with a variable cache instance like this.
def user_data(user_id) @user_data || = User.find(user_id).data end
but the @user_data instance @user_data will only be assigned a value the first time it is zero, and after it stores the data for the user, let's say that for user_id is 1, and when I pass user_id 2 in this method, it returns the data for user_id 1, because it will not allocate a new value for it, so my question is how can I cache its value based on function parameters.
source share