Class: FastSerializer::Cache

Inherits:
Object
  • Object
show all
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

ActiveSupportCache

Defined Under Namespace

Classes: ActiveSupportCache

Instance Method Summary collapse

Instance Method Details

#fetch(serializer, ttl, &block) ⇒ Object

Raises:

  • (NotImplementedError)


5
6
7
# File 'lib/fast_serializer/cache.rb', line 5

def fetch(serializer, ttl, &block)
  raise NotImplementedError
end

#fetch_all(serializers, ttl) ⇒ 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.



14
15
16
17
18
19
20
# File 'lib/fast_serializer/cache.rb', line 14

def fetch_all(serializers, ttl)
  serializers.collect do |serializer|
    fetch(serializer, ttl) do
      yield(serializer)
    end
  end
end