Sha256: d5994ad4637eb961132c8e4b0d2791edc816d2175cd5462c22b171b554743851

Contents?: true

Size: 610 Bytes

Versions: 3

Compression:

Stored size: 610 Bytes

Contents

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

3 entries across 3 versions & 1 rubygems

Version Path
fast_serializer-1.1.1 lib/fast_serializer/cache/active_support_cache.rb
fast_serializer-1.1.0 lib/fast_serializer/cache/active_support_cache.rb
fast_serializer-1.0.2 lib/fast_serializer/cache/active_support_cache.rb