Sha256: bdded4902bfddd11a9342449fbc18d683bf12833225713e613c16db8d73f9c7f

Contents?: true

Size: 632 Bytes

Versions: 2

Compression:

Stored size: 632 Bytes

Contents

# frozen_string_literal: true

module FastSerializer
  # ActiveSupport compatible cache implementation.
  class Cache::ActiveSupportCache < Cache
    attr_reader :cache

    def initialize(cache)
      @cache = cache
    end

    def fetch(serializer, ttl)
      @cache.fetch(serializer.cache_key, expires_in: ttl) do
        yield(serializer)
      end
    end

    def fetch_all(serializers, ttl)
      results = @cache.fetch_multi(*serializers) { |serializer| yield(serializer) }
      if results.is_a?(Hash)
        serializers.collect { |serializer| results[serializer] }
      else
        results
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
fast_serializer-1.1.4 lib/fast_serializer/cache/active_support_cache.rb
fast_serializer-1.1.3 lib/fast_serializer/cache/active_support_cache.rb