Class: FastSerializer::Cache
- Inherits:
-
Object
- Object
- FastSerializer::Cache
- Defined in:
- lib/fast_serializer/cache.rb
Overview
Base class for cache implementations for storing cacheable serializers. Implementations must implement the fetch method.
Direct Known Subclasses
Defined Under Namespace
Classes: ActiveSupportCache
Instance Method Summary collapse
-
#fetch(serializer, ttl) {|serializer| ... } ⇒ Object
Fetch a serialized value from the cache.
-
#fetch_all(serializers, ttl) {|serializer| ... } ⇒ Array<Object>
Fetch multiple serializers from the cache.
Instance Method Details
#fetch(serializer, ttl) {|serializer| ... } ⇒ Object
Fetch a serialized value from the cache. If the value is not cached, the block will be yielded to to generate the value.
14 15 16 |
# File 'lib/fast_serializer/cache.rb', line 14 def fetch(serializer, ttl, &block) raise NotImplementedError end |
#fetch_all(serializers, ttl) {|serializer| ... } ⇒ Array<Object>
Fetch multiple serializers from the cache. The default behavior is just to call fetch with each serializer. Implementations may optimize this if the cache can return multiple values at once.
The block to this method will be yielded to with each uncached serializer.
28 29 30 31 32 33 34 |
# File 'lib/fast_serializer/cache.rb', line 28 def fetch_all(serializers, ttl) serializers.collect do |serializer| fetch(serializer, ttl) do yield(serializer) end end end |