Skip to content

Conversation

@DharmaPriya-V
Copy link

@DharmaPriya-V DharmaPriya-V commented May 16, 2023

Currently in identity cache we can't able to set the model level TTL, it can be set only globally through the cache store.
But in many cases for different models we might require different expiry time. Here while yielding the actual result to write to the cache we can set the expiry time.

In each model you can specify the constant value of expire_time, in the cache _value formation we can check if the constant is defined if so we can add the value with the key cache_expire to the result hash.

Class Model1 < ApplicationRecord
  EXPIRE_CACHE = 24 * 60 * 60 # expiry of 1 day
end

This EXPIRE_CACHE will be retrieved and cached with this time for any record belonging to this model. All we have to do is to just set the cache constant value at the model level in the application

Glad to hear other thoughts as well

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant