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
params [Hash] options option options [String] :namespace option options [ActiveSupport::Duration] :created_before - provide a time duration after record without expire_at date will get removed.
-
#clear(options = nil) ⇒ Boolean
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
params [Hash] options option options [String] :namespace option options [ActiveSupport::Duration] :created_before - provide a time duration after record without expire_at date will get removed.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/active_support/cache/database_store.rb', line 33 def cleanup( = nil) = () scope = @model.expired if (created_before = [:created_before]) scope = scope.or(@model.created_before(created_before)) end if (namespace = [:namespace]) scope = scope.namespaced(namespace) end scope.delete_all end |
#clear(options = nil) ⇒ Boolean
Clears the entire cache. Be careful with this method.
params [Hash] options option options [String] :namespace
54 55 56 57 58 59 60 61 62 |
# File 'lib/active_support/cache/database_store.rb', line 54 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.
65 66 67 68 69 70 71 72 73 |
# File 'lib/active_support/cache/database_store.rb', line 65 def count( = nil) = () scope = @model.all if (namespace = [:namespace]) scope = scope.namespaced(namespace) end scope = scope.fresh unless [:all] scope.count end |