Sha256: 4ed54f5df9b79fbbe48e06862fdd281ef37a9398bbff01f73e3e692d9d24f773

Contents?: true

Size: 620 Bytes

Versions: 12

Compression:

Stored size: 620 Bytes

Contents

module DistributeReads
  class CacheStore
    def read(key)
      memory_cached = memory_store.read(key)
      return nil if memory_cached == :nil
      return memory_cached if memory_cached

      store_cached = store.try(:read, key)
      memory_store.write(key, store_cached || :nil)
      store_cached
    end

    def write(*args)
      memory_store.write(*args)
      store.try(:write, *args)
    end

    private

    # use ActiveSupport::Cache::MemoryStore instead?
    def memory_store
      @memory_store ||= Makara::Cache::MemoryStore.new
    end

    def store
      @store ||= Rails.cache
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
distribute_reads-0.4.0 lib/distribute_reads/cache_store.rb
distribute_reads-0.3.5 lib/distribute_reads/cache_store.rb
distribute_reads-0.3.4 lib/distribute_reads/cache_store.rb
distribute_reads-0.3.3 lib/distribute_reads/cache_store.rb
distribute_reads-0.3.2 lib/distribute_reads/cache_store.rb
distribute_reads-0.3.1 lib/distribute_reads/cache_store.rb
distribute_reads-0.3.0 lib/distribute_reads/cache_store.rb
distribute_reads-0.2.4 lib/distribute_reads/cache_store.rb
distribute_reads-0.2.3 lib/distribute_reads/cache_store.rb
distribute_reads-0.2.2 lib/distribute_reads/cache_store.rb
distribute_reads-0.2.1 lib/distribute_reads/cache_store.rb
distribute_reads-0.2.0 lib/distribute_reads/cache_store.rb