Sha256: b80a11f94d5246b3abeac0b23ecca3efe55ef46a0f2b91b63248f86421cb1165

Contents?: true

Size: 567 Bytes

Versions: 2

Compression:

Stored size: 567 Bytes

Contents

module Spreeference
  class ScopedStore
    def initialize prefix, suffix=nil
      @prefix = prefix
      @suffix = suffix
    end

    def store
      Spreeference::Store.instance
    end

    def fetch key, &block
      store.fetch(key_for(key), &block)
    end

    def []= key, value
      store[key_for(key)] = value
    end

    def delete key
      store.delete(key_for(key))
    end

    private
    def key_for key
      [rails_cache_id, @prefix, key, @suffix].compact.join('/')
    end

    def rails_cache_id
      ENV['RAILS_CACHE_ID']
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
spreeference-0.1.1 lib/spreeference/scoped_store.rb
spreeference-0.1.0 lib/spreeference/scoped_store.rb