class FastSerializer::Cache

Base class for cache implementations for storing cacheable serializers. Implementations must implement the fetch method.

Public Instance Methods

fetch(serializer, ttl, &block) click to toggle source
# File lib/fast_serializer/cache.rb, line 7
def fetch(serializer, ttl, &block)
  raise NotImplementedError
end
fetch_all(serializers, ttl) { |serializer| ... } click to toggle source

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.

# File lib/fast_serializer/cache.rb, line 16
def fetch_all(serializers, ttl)
  serializers.collect do |serializer|
    fetch(serializer, ttl) do
      yield(serializer)
    end
  end
end