class Store
Ruby on Rails 7.2.3
Active Support Cache Store
An abstract cache store class. There are multiple cache store implementations, each having its own additional features. See the classes under the ActiveSupport::Cache module, e.g. ActiveSupport::Cache::MemCacheStore. MemCacheStore is currently the most popular cache store for large production websites.
Some implementations may not support all methods beyond the basic cache methods of #fetch, #write, #read, #exist?, and #delete.
ActiveSupport::Cache::Store can store any Ruby object that is supported by its coder‘s dump and load methods.
cache = ActiveSupport::Cache::MemoryStore.new
cache.read('city') # => nil
cache.write('city', "Duckburgh") # => true
cache.read('city') # => "Duckburgh"
cache.write('not serializable', Proc.new {}) # => TypeError
Keys are always translated into Strings and are case sensitive. When an object is specified as a key and has a cache_key method defined, this method will be called to define the key. Otherwise, the to_param method will be called. Hashes and Arrays can also be used as keys. The elements will be delimited by slashes, and the elements within a Hash will be sorted by key so they are consistent.
cache.read('city') == cache.read(:city) # => true
Nil values can be cached.
If your cache is on a shared infrastructure, you can define a namespace for your cache entries. If a namespace is defined, it will be prefixed on to every key. The namespace can be either a static value or a Proc. If it is a Proc, it will be invoked when each key is evaluated so that you can use application logic to invalidate keys.
cache.namespace = -> { @last_mod_time } # Set the namespace to a variable
@last_mod_time = Time.now # Invalidate the entire cache by changing namespace
Inherits from
Constants
Attributes
Methods (defined here)
- # cleanup
- # clear
- # decrement
- # delete
- # delete_matched
- # delete_multi
- # exist?
- # fetch
- # fetch_multi
- # increment
- # mute
- # read
- # read_multi
- # silence!
- # write
- # write_multi
- self. new
Private methods (26)
Show private methods Implementation detail — not part of the public API.
- # default_serializer
- # delete_entry
- # delete_multi_entries
- # deserialize_entry
- # expanded_key
- # expanded_version
- # get_entry_value
- # handle_expired_entry
- # handle_invalid_expires_in
- # _instrument
- # instrument
- # instrument_multi
- # key_matcher
- # merged_options
- # namespace_key
- # normalize_key
- # normalize_options
- # normalize_version
- # read_entry
- # read_multi_entries
- # save_block_result_to_cache
- # serialize_entry
- # validate_options
- # write_entry
- # write_multi_entries
- self. retrieve_pool_options
Used by
Subclasses (5)
Methods (inherited)
From Object
(17)
- # acts_like?
- # blank?
- # deep_dup
- # duplicable?
- # html_safe?
- # in?
- # instance_values
- # instance_variable_names
- # presence
- # presence_in
- # present?
- # to_param
- # to_query
- # try
- # try!
- # with
- # with_options
From ActiveSupport::NumericWithFormat
(2)
- # to_formatted_s
- # to_fs