Class: ConvenientService::Support::Cache::Entities::Caches::Hash Private
- Defined in:
- lib/convenient_service/support/cache/entities/caches/hash.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Direct Known Subclasses
Instance Attribute Summary
Attributes inherited from Base
#default, #key, #parent, #store
Instance Method Summary collapse
- #backend ⇒ Symbol private
- #clear ⇒ ConvenientService::Support::Cache::Entities::Caches::Hash private
-
#default=(value) ⇒ Object
private
Can be any type.
-
#delete(key) ⇒ Object
private
Can be any type.
- #empty? ⇒ Boolean private
- #exist?(key) ⇒ Boolean private
-
#fetch(key, &block) ⇒ Object
private
Can be any type.
- #initialize(store: {}, **kwargs) ⇒ void constructor private
-
#read(key) ⇒ Object
private
Can be any type.
-
#scope(key, backed_by: backend, default: self.default) ⇒ ConvenientService::Support::Cache::Entities::Caches::Base
private
Creates a scoped cache.
-
#scope!(key, backed_by: backend, default: self.default) ⇒ ConvenientService::Support::Cache::Entities::Caches::Base
private
Creates a scoped cache.
-
#write(key, value) ⇒ Object
private
Can be any type.
Methods inherited from Base
#==, #[], #[]=, #get, keygen, #keygen, #set
Methods included from AbstractMethod
Methods included from ConvenientService::Support::Concern
Constructor Details
#initialize(store: {}, **kwargs) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
18 19 20 |
# File 'lib/convenient_service/support/cache/entities/caches/hash.rb', line 18 def initialize(store: {}, **kwargs) super(store: ::Hash.new(kwargs[:default]).update(store), **kwargs) end |
Instance Method Details
#backend ⇒ Symbol
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
25 26 27 |
# File 'lib/convenient_service/support/cache/entities/caches/hash.rb', line 25 def backend Constants::Backends::HASH end |
#clear ⇒ ConvenientService::Support::Cache::Entities::Caches::Hash
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
109 110 111 112 113 |
# File 'lib/convenient_service/support/cache/entities/caches/hash.rb', line 109 def clear store.clear self end |
#default=(value) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns Can be any type.
149 150 151 152 153 154 155 |
# File 'lib/convenient_service/support/cache/entities/caches/hash.rb', line 149 def default=(value) save_self_as_scope_in_parent! store.default = value @default = value end |
#delete(key) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns Can be any type.
98 99 100 101 102 103 104 |
# File 'lib/convenient_service/support/cache/entities/caches/hash.rb', line 98 def delete(key) value = store.delete(key) delete_self_as_scope_in_parent! if store.empty? value end |
#empty? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
35 36 37 |
# File 'lib/convenient_service/support/cache/entities/caches/hash.rb', line 35 def empty? store.empty? end |
#exist?(key) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
46 47 48 |
# File 'lib/convenient_service/support/cache/entities/caches/hash.rb', line 46 def exist?(key) store.has_key?(key) end |
#fetch(key, &block) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns Can be any type.
83 84 85 86 87 88 89 |
# File 'lib/convenient_service/support/cache/entities/caches/hash.rb', line 83 def fetch(key, &block) return store[key] unless block save_self_as_scope_in_parent! store.fetch(key) { store[key] = yield } end |
#read(key) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns Can be any type.
57 58 59 |
# File 'lib/convenient_service/support/cache/entities/caches/hash.rb', line 57 def read(key) store[key] end |
#scope(key, backed_by: backend, default: self.default) ⇒ ConvenientService::Support::Cache::Entities::Caches::Base
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Creates a scoped cache. Parent cache is modified on the first write to the scoped cache.
126 127 128 |
# File 'lib/convenient_service/support/cache/entities/caches/hash.rb', line 126 def scope(key, backed_by: backend, default: self.default) store.fetch(key) { Support::Cache.backed_by(backed_by).new(default: default, parent: self, key: key) } end |
#scope!(key, backed_by: backend, default: self.default) ⇒ ConvenientService::Support::Cache::Entities::Caches::Base
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Creates a scoped cache. Parent cache is modified immediately.
141 142 143 |
# File 'lib/convenient_service/support/cache/entities/caches/hash.rb', line 141 def scope!(key, backed_by: backend, default: self.default) store.fetch(key) { store[key] = Support::Cache.backed_by(backed_by).new(default: default, parent: self, key: key) } end |
#write(key, value) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns Can be any type.
69 70 71 72 73 |
# File 'lib/convenient_service/support/cache/entities/caches/hash.rb', line 69 def write(key, value) save_self_as_scope_in_parent! store[key] = value end |