class Sprockets::Cache::MemoryStore
Experimental RBS support (using type sampling data from the type_fusion
project).
# sig/sprockets/cache/memory_store.rbs class Sprockets::Cache::MemoryStore def get: (String key) -> String? def set: (String key, (String | Hash) value) -> untyped end
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 clear(options=nil)
Public: Clear the cache
def clear(options=nil) @mutex.synchronize do @cache.clear end true end
def get(key)
Experimental RBS support (using type sampling data from the type_fusion
project).
def get: (String key) -> String?
This signature was generated using 55 samples from 3 applications.
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) @mutex.synchronize do exists = true value = @cache.delete(key) { exists = false } if exists @cache[key] = value else nil end end end
def initialize(max_size = DEFAULT_MAX_SIZE)
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 = {} @mutex = Mutex.new end
def inspect
Public: Pretty inspect
def inspect @mutex.synchronize do "#<#{self.class} size=#{@cache.size}/#{@max_size}>" end end
def set(key, value)
Experimental RBS support (using type sampling data from the type_fusion
project).
def set: (String key, (String | uri | String | load_path | String | filename | String | name | String | logical_path | String | content_type | String | source | NilClass | metadata | digest | String | length | Integer | dependencies | Set | environment_version | String | dependencies_digest | String | id | String) value) -> untyped
This signature was generated using 31 samples from 1 application.
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) @mutex.synchronize do @cache.delete(key) @cache[key] = value @cache.shift if @cache.size > @max_size end value end