Class: AtomicCache::Keyspace
- Inherits:
-
Object
- Object
- AtomicCache::Keyspace
- Defined in:
- lib/atomic_cache/key/keyspace.rb
Constant Summary collapse
- DEFAULT_SEPARATOR =
':'
- LOCK_VALUE =
1
- PRIMITIVE_CLASSES =
[Numeric, String, Symbol]
Instance Attribute Summary collapse
-
#namespace ⇒ Object
readonly
Returns the value of attribute namespace.
-
#root ⇒ Object
readonly
Returns the value of attribute root.
Instance Method Summary collapse
-
#child(namespace) ⇒ AtomicCache::Keyspace
Create a new Keyspace, extending the namespace with the given segments and retaining this keyspace’s root and separator.
-
#initialize(namespace:, root: nil, separator: nil, timestamp_formatter: nil) ⇒ Keyspace
constructor
A new instance of Keyspace.
-
#key(suffix = nil) ⇒ String
Get a string key for this keyspace, optionally suffixed by the given value.
-
#last_known_key_key ⇒ Object
the key the last_known_key is stored at, thus key key.
- #last_mod_time_key ⇒ Object
- #lock_key ⇒ Object
Constructor Details
#initialize(namespace:, root: nil, separator: nil, timestamp_formatter: nil) ⇒ Keyspace
Returns a new instance of Keyspace.
22 23 24 25 26 27 28 |
# File 'lib/atomic_cache/key/keyspace.rb', line 22 def initialize(namespace:, root: nil, separator: nil, timestamp_formatter: nil) = || DefaultConfig.instance. @separator = separator || DefaultConfig.instance.separator @namespace = [] @namespace = normalize_segments(namespace) if namespace.present? @root = root || @namespace.last end |
Instance Attribute Details
#namespace ⇒ Object (readonly)
Returns the value of attribute namespace.
16 17 18 |
# File 'lib/atomic_cache/key/keyspace.rb', line 16 def namespace @namespace end |
#root ⇒ Object (readonly)
Returns the value of attribute root.
16 17 18 |
# File 'lib/atomic_cache/key/keyspace.rb', line 16 def root @root end |
Instance Method Details
#child(namespace) ⇒ AtomicCache::Keyspace
Create a new Keyspace, extending the namespace with the given segments and retaining this keyspace’s root and separator
35 36 37 38 39 |
# File 'lib/atomic_cache/key/keyspace.rb', line 35 def child(namespace) throw ArgumentError.new("Prefix must be an Array but was #{namespace.class}") unless namespace.is_a?(Array) joined_namespacees = @namespace.clone.concat(namespace) self.class.new(namespace: joined_namespacees) end |
#key(suffix = nil) ⇒ String
Get a string key for this keyspace, optionally suffixed by the given value
45 46 47 |
# File 'lib/atomic_cache/key/keyspace.rb', line 45 def key(suffix=nil) flattened_key(suffix) end |
#last_known_key_key ⇒ Object
the key the last_known_key is stored at, thus key key.
58 59 60 |
# File 'lib/atomic_cache/key/keyspace.rb', line 58 def last_known_key_key @last_known_key ||= flattened_key('lkk') end |
#last_mod_time_key ⇒ Object
49 50 51 |
# File 'lib/atomic_cache/key/keyspace.rb', line 49 def last_mod_time_key @last_mod_time_key ||= flattened_key('lmt') end |
#lock_key ⇒ Object
53 54 55 |
# File 'lib/atomic_cache/key/keyspace.rb', line 53 def lock_key @lock_key ||= flattened_key('lock') end |