Class: ConvenientService::Support::Cache::Entities::Caches::Array Private
- Defined in:
- lib/convenient_service/support/cache/entities/caches/array.rb,
lib/convenient_service/support/cache/entities/caches/array/entities/pair.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
Defined Under Namespace
Modules: Entities
Instance Attribute Summary
Attributes inherited from Base
#default, #key, #parent, #store
Instance Method Summary collapse
- #backend ⇒ Symbol private
- #clear ⇒ ConvenientService::Support::Cache::Entities::Caches::Array 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.
20 21 22 |
# File 'lib/convenient_service/support/cache/entities/caches/array.rb', line 20 def initialize(store: [], **kwargs) super(store: ::Array.new(0, kwargs[:default]).concat(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.
27 28 29 |
# File 'lib/convenient_service/support/cache/entities/caches/array.rb', line 27 def backend Constants::Backends::ARRAY end |
#clear ⇒ ConvenientService::Support::Cache::Entities::Caches::Array
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.
100 101 102 103 104 |
# File 'lib/convenient_service/support/cache/entities/caches/array.rb', line 100 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.
144 145 146 147 148 |
# File 'lib/convenient_service/support/cache/entities/caches/array.rb', line 144 def default=(value) save_self_as_scope_in_parent! @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.
87 88 89 90 91 92 93 94 95 |
# File 'lib/convenient_service/support/cache/entities/caches/array.rb', line 87 def delete(key) index = index(key) value = store.delete_at(index).value if index 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.
34 35 36 |
# File 'lib/convenient_service/support/cache/entities/caches/array.rb', line 34 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.
42 43 44 |
# File 'lib/convenient_service/support/cache/entities/caches/array.rb', line 42 def exist?(key) index(key) ? true : false 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.
79 80 81 |
# File 'lib/convenient_service/support/cache/entities/caches/array.rb', line 79 def fetch(key, &block) _fetch(key, default: default, &block) 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.
50 51 52 53 54 |
# File 'lib/convenient_service/support/cache/entities/caches/array.rb', line 50 def read(key) index = index(key) index ? store[index].value : default 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.
117 118 119 120 121 122 123 |
# File 'lib/convenient_service/support/cache/entities/caches/array.rb', line 117 def scope(key, backed_by: backend, default: self.default) Utils.with_one_time_object do |undefined| value = _fetch(key, default: undefined) (value == undefined) ? Support::Cache.backed_by(backed_by).new(default: default, parent: self, key: key) : value end 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.
136 137 138 |
# File 'lib/convenient_service/support/cache/entities/caches/array.rb', line 136 def scope!(key, backed_by: backend, default: self.default) _fetch(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.
61 62 63 64 65 66 67 68 69 |
# File 'lib/convenient_service/support/cache/entities/caches/array.rb', line 61 def write(key, value) index = index(key) || store.size save_self_as_scope_in_parent! store[index] = pair(key, value) value end |