class Sprockets::Cache::MemoryStore


ActiveSupport::Cache::MemoryStore
See Also
environment.cache = Sprockets::Cache::MemoryStore.new(1000)
Assign the instance to the Environment#cache.
Public: Basic in memory LRU cache.

def get(key)

Returns Object or nil or the value is not set.

key - String cache key.

This API should not be used directly, but via the Cache wrapper API.

Public: Retrieve value from cache.
def get(key)
  exists = true
  value = @cache.delete(key) { exists = false }
  if exists
    @cache[key] = value
  else
    nil
  end
end

def initialize(max_size = DEFAULT_MAX_SIZE)

(default: 1000).
max_size - A Integer of the maximum number of keys the store will hold.

Public: Initialize the cache store.
def initialize(max_size = DEFAULT_MAX_SIZE)
  @max_size = max_size
  @cache = {}
end

def inspect

Returns String.

Public: Pretty inspect
def inspect
  "#<#{self.class} size=#{@cache.size}/#{@max_size}>"
end

def set(key, value)

Returns Object value.

value - Object value.
key - String cache key.

This API should not be used directly, but via the Cache wrapper API.

Public: Set a key and value in the cache.
def set(key, value)
  @cache.delete(key)
  @cache[key] = value
  @cache.shift if @cache.size > @max_size
  value
end