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) {|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.

Parameters:

  • serializer (FastSerializer::Serializer)

    The serializer to fetch the value for.

  • ttl (Numeric)

    The time to live for the cached value.

Yield Parameters:

Returns:

  • (Object)

    The serialized value.

Raises:

  • (NotImplementedError)


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.

Parameters:

  • serializers (Array<FastSerializer::Serializer>)

    The serializers to fetch the values for.

  • ttl (Numeric)

    The time to live for the cached values.

Yield Parameters:

Returns:

  • (Array<Object>)

    The serialized values.



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