Class: FastSerializer::Cache::ActiveSupportCache
- Inherits:
-
FastSerializer::Cache
- Object
- FastSerializer::Cache
- FastSerializer::Cache::ActiveSupportCache
- Defined in:
- lib/fast_serializer/cache/active_support_cache.rb
Overview
ActiveSupport compatible cache implementation.
Instance Attribute Summary collapse
-
#cache ⇒ Object
readonly
Returns the value of attribute cache.
Instance Method Summary collapse
- #fetch(serializer, ttl) ⇒ Object
- #fetch_all(serializers, ttl) ⇒ Object
-
#initialize(cache) ⇒ ActiveSupportCache
constructor
A new instance of ActiveSupportCache.
Constructor Details
#initialize(cache) ⇒ ActiveSupportCache
Returns a new instance of ActiveSupportCache.
8 9 10 |
# File 'lib/fast_serializer/cache/active_support_cache.rb', line 8 def initialize(cache) @cache = cache end |
Instance Attribute Details
#cache ⇒ Object (readonly)
Returns the value of attribute cache.
6 7 8 |
# File 'lib/fast_serializer/cache/active_support_cache.rb', line 6 def cache @cache end |
Instance Method Details
#fetch(serializer, ttl) ⇒ Object
12 13 14 15 16 |
# File 'lib/fast_serializer/cache/active_support_cache.rb', line 12 def fetch(serializer, ttl) @cache.fetch(serializer.cache_key, expires_in: ttl) do yield(serializer) end end |
#fetch_all(serializers, ttl) ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/fast_serializer/cache/active_support_cache.rb', line 18 def fetch_all(serializers, ttl) results = @cache.fetch_multi(*serializers) { |serializer| yield(serializer) } if results.is_a?(Hash) serializers.collect { |serializer| results[serializer] } else results end end |