Sha256: e25a15aa852a40432a9aa0e52d35b403892e37c43cd1652985665b4ecd939ec2

Contents?: true

Size: 594 Bytes

Versions: 5

Compression:

Stored size: 594 Bytes

Contents

class APICache
  class MonetaStore < APICache::AbstractStore
    def initialize(store)
      @moneta = store
    end

    # Set value. Returns true if success.
    def set(key, value)
      @moneta[key] = value
      @moneta["#{key}_created_at"] = Time.now
      true
    end

    # Get value.
    def get(key)
      @moneta[key]
    end

    # Does a given key exist in the cache?
    def exists?(key)
      @moneta.key?(key)
    end

    # Has a given time passed since the key was set?
    def expired?(key, timeout)
      Time.now - @moneta["#{key}_created_at"] > timeout
    end
  end
end

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
mloughran-api_cache-0.2.0 lib/api_cache/moneta_store.rb
api_cache-0.2.3 lib/api_cache/moneta_store.rb
api_cache-0.2.2 lib/api_cache/moneta_store.rb
api_cache-0.2.1 lib/api_cache/moneta_store.rb
api_cache-0.2.0 lib/api_cache/moneta_store.rb