You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In my use case, I have 2 separate issues that I've come across with the current implementation of the object_cache_key method.
The first is when I use a PORO object that does not have an updated_at attribute, I've defined a cache key, but object_cache_key does not look for that until after it builds object_time_safe and therefore throws an error.
I overrode object_cache_key in my app to look to see if cache_key is defined up front and just use that is it's there.
My other issue is, there are times I use different adapters for the same object in different parts of the app. Since different adapters use the same cache_key, the second adapter to get used returns the wrong format.
I overrode object_cache_key to include the adapter in the cache key to prevent this.
Here is my override.
# overridden so it uses the object's cache key if it's defined instead of only calling it if @klass._cache_key is not present
# and to include the adapter type in the cache key.
def object_cache_key
@klass._cache_options = Hash(@klass._cache_options) # while we are overriding things, we might as well convert nil options to a Hash to prevent a ReadThis error.
if @cached_serializer.object.respond_to? :cache_key
cache_key = "#{self.class.to_s.demodulize.underscore}/#{@cached_serializer.object.cache_key}"
cache_key.gsub!(cache_key.split('/').second, @klass._cache_key.to_s) if @klass._cache_key
return cache_key
end
object_time_safe = @cached_serializer.object.updated_at
object_time_safe = object_time_safe.strftime('%Y%m%d%H%M%S%9N') if object_time_safe.respond_to?(:strftime)
"#{self.class.to_s.demodulize.underscore}/#{@klass._cache_key}/#{@cached_serializer.object.id}-#{object_time_safe}"
end
The text was updated successfully, but these errors were encountered:
In my use case, I have 2 separate issues that I've come across with the current implementation of the
object_cache_key
method.The first is when I use a PORO object that does not have an
updated_at
attribute, I've defined a cache key, butobject_cache_key
does not look for that until after it buildsobject_time_safe
and therefore throws an error.I overrode
object_cache_key
in my app to look to see ifcache_key
is defined up front and just use that is it's there.My other issue is, there are times I use different adapters for the same object in different parts of the app. Since different adapters use the same cache_key, the second adapter to get used returns the wrong format.
I overrode
object_cache_key
to include the adapter in the cache key to prevent this.Here is my override.
The text was updated successfully, but these errors were encountered: