I am using redis cache to fetch data in my rails applications. In simple words I can say that I have two application first is based on rails 4 and second is on rails 6. I have to use cache data in both application.
In rails 4 application :- I have created cache in rails 4 application and It fetched data successfully.
Rails.cache.fetch("test_cache"){User.last}
=> #<User id: 100973, email: "xxxx.com", encrypted_password: "$2a$10$D8aOhoSWvNWeEQE2swAX2OEVIF5H0aY8sR/fGVQ3BhU...........>
In rails 6 application :- But When I want to load same cache in my rails 6 application gives me an error.
Rails.cache.fetch("test_cache"){User.last}
Traceback (most recent call last):
2: from (irb):18
1: from (irb):18:in `rescue in irb_binding'
NameError (uninitialized constant ActiveRecord::AttributeSet)
Did you mean? ActiveRecord::Attributes
Then I came to one solution, save data with as_json
Rails.cache.fetch("test_cache"){User.last.as_json}
which successfully work and fetched data on both application but then I have one more problem how can I access model methods, associations etc etc...
for the same.
Any suggestion or any idea ?