Class: ActiveSupport::Cache::DatabaseStore
- Inherits:
-
Store
- Object
- Store
- ActiveSupport::Cache::DatabaseStore
- Includes:
- Strategy::LocalCache
- Defined in:
- lib/active_support/cache/database_store.rb,
lib/active_support/cache/database_store/model.rb,
lib/active_support/cache/database_store/migration.rb
Overview
A cache store implementation which stores everything in the database, using ActiveRecord as the backend.
DatabaseStore implements the Strategy::LocalCache strategy which implements an in-memory cache inside of a block.
Defined Under Namespace
Class Method Summary collapse
-
.supports_cache_versioning? ⇒ Boolean
Advertise cache versioning support.
Instance Method Summary collapse
-
#cleanup(options = nil) ⇒ Object
Preemptively iterates through all stored keys and removes the ones which have expired.
-
#clear(options = nil) ⇒ Object
Clears the entire cache.
-
#count(options = nil) ⇒ Object
Calculates the number of entries in the cache.
-
#initialize(options = nil) ⇒ DatabaseStore
constructor
param [Hash] options options option options [Class] :model model class.
Constructor Details
#initialize(options = nil) ⇒ DatabaseStore
param [Hash] options options option options [Class] :model model class. Default: ActiveSupport::Cache::DatabaseStore::Model
23 24 25 26 |
# File 'lib/active_support/cache/database_store.rb', line 23 def initialize( = nil) @model = ( || {}).delete(:model) || Model super() end |
Class Method Details
.supports_cache_versioning? ⇒ Boolean
Advertise cache versioning support.
17 18 19 |
# File 'lib/active_support/cache/database_store.rb', line 17 def self.supports_cache_versioning? true end |
Instance Method Details
#cleanup(options = nil) ⇒ Object
Preemptively iterates through all stored keys and removes the ones which have expired.
29 30 31 32 33 34 35 36 |
# File 'lib/active_support/cache/database_store.rb', line 29 def cleanup( = nil) = () scope = @model.expired if (namespace = [:namespace]) scope = scope.namespaced(namespace) end scope.delete_all end |
#clear(options = nil) ⇒ Object
Clears the entire cache. Be careful with this method.
39 40 41 42 43 44 45 46 47 |
# File 'lib/active_support/cache/database_store.rb', line 39 def clear( = nil) = () if (namespace = [:namespace]) @model.namespaced(namespace).delete_all else @model.truncate! end true end |
#count(options = nil) ⇒ Object
Calculates the number of entries in the cache.
50 51 52 53 54 55 56 57 58 |
# File 'lib/active_support/cache/database_store.rb', line 50 def count( = nil) = () scope = @model.all if (namespace = [:namespace]) scope = scope.namespaced(namespace) end scope = scope.fresh unless [:all] scope.count end |