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
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
18 19 20 21 |
# File 'lib/active_support/cache/database_store.rb', line 18 def initialize(=nil) @model = ( || {}).delete(:model) || Model super() end |
Instance Method Details
#cleanup(options = nil) ⇒ Object
Preemptively iterates through all stored keys and removes the ones which have expired.
24 25 26 27 28 29 30 31 |
# File 'lib/active_support/cache/database_store.rb', line 24 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.
34 35 36 37 38 39 40 41 42 |
# File 'lib/active_support/cache/database_store.rb', line 34 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.
45 46 47 48 49 50 51 52 53 |
# File 'lib/active_support/cache/database_store.rb', line 45 def count(=nil) = () scope = @model.all if (namespace = [:namespace]) scope = scope.namespaced(namespace) end scope = scope.fresh unless [:all] scope.count end |