class Store
Ruby on Rails 7.0.10
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")
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
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 (23)
Show private methods Implementation detail — not part of the public API.
- # default_coder
- # delete_entry
- # delete_multi_entries
- # deserialize_entry
- # expanded_key
- # expanded_version
- # get_entry_value
- # handle_expired_entry
- # instrument
- # key_matcher
- # merged_options
- # namespace_key
- # normalize_key
- # normalize_options
- # normalize_version
- # read_entry
- # read_multi_entries
- # save_block_result_to_cache
- # serialize_entry
- # write_entry
- # write_multi_entries
- self. ensure_connection_pool_added!
- self. retrieve_pool_options
Used by
Subclasses (5)
Methods (inherited)
From Object
(16)
- # 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_options
From ActiveRecord::TestFixtures
(4)
From ActiveSupport::Concern
(3)
- # class_methods
- # included
- # prepended