Sha256: 76590ed2be533e3e39ce44544e15a198d571b98a2f202bd45eb214fd2ba9fad9

Contents?: true

Size: 730 Bytes

Versions: 2

Compression:

Stored size: 730 Bytes

Contents

module FastSerializer
  # Base class for cache implementations for storing cacheable serializers.
  # Implementations must implement the +fetch+ method.
  class Cache
    def fetch(serializer, ttl, &block)
      raise NotImplementedError
    end
    
    # 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.
    def fetch_all(serializers, ttl)
      serializers.collect do |serializer|
        fetch(serializer, ttl) do
          yield(serializer)
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
fast_serializer-1.0.1 lib/fast_serializer/cache.rb
fast_serializer-1.0.0 lib/fast_serializer/cache.rb