Sha256: 1d99e58a08b6e4e5823195551f77528347f6c9c18221a0fa824afe6e49c24356

Contents?: true

Size: 865 Bytes

Versions: 2

Compression:

Stored size: 865 Bytes

Contents

module Lawnchair
  module StorageEngine
    class Abstract
      class << self
        attr_reader :cache_container
        
        def cache_container
          @cache_container ||= {}
        end
      
        def fetch(key, options, &block)
          if exists?(key)
            value = get(key, options)
          else
            value = block.call
            set(key, value, options)
          end
          value
        end
      
        def get(key, options={})
          if options[:raw]
            cache_container[computed_key(key)]
          else
            exists?(key) ? Marshal.load(cache_container[computed_key(key)]) : nil
          end
        end
      
        def computed_key(key)
          raise "Missiing key" if key.nil? || key.empty?
          prefix = "Lawnchair"
          "#{prefix}:#{key}"
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
lawnchair-0.5.1 lib/storage_engine/abstract.rb
lawnchair-0.5.0 lib/storage_engine/abstract.rb