Class: Cachext::Key
- Inherits:
-
Object
- Object
- Cachext::Key
- Defined in:
- lib/cachext/key.rb
Instance Attribute Summary collapse
-
#raw ⇒ Object
readonly
Returns the value of attribute raw.
Instance Method Summary collapse
- #backup ⇒ Object
- #clear ⇒ Object
- #delete_backup ⇒ Object
- #digest ⇒ Object
-
#initialize(raw, config: Cachext.config) ⇒ Key
constructor
A new instance of Key.
- #inspect ⇒ Object
- #locked? ⇒ Boolean
- #read ⇒ Object
- #read_backup ⇒ Object
- #write(value, options = {}) ⇒ Object
- #write_backup(value) ⇒ Object
Constructor Details
#initialize(raw, config: Cachext.config) ⇒ Key
Returns a new instance of Key.
5 6 7 8 |
# File 'lib/cachext/key.rb', line 5 def initialize(raw, config: Cachext.config) @raw = Array(raw) @config = config end |
Instance Attribute Details
#raw ⇒ Object (readonly)
Returns the value of attribute raw.
3 4 5 |
# File 'lib/cachext/key.rb', line 3 def raw @raw end |
Instance Method Details
#backup ⇒ Object
18 19 20 |
# File 'lib/cachext/key.rb', line 18 def backup [:backup_cache] + raw end |
#clear ⇒ Object
34 35 36 |
# File 'lib/cachext/key.rb', line 34 def clear cache.delete raw end |
#delete_backup ⇒ Object
46 47 48 |
# File 'lib/cachext/key.rb', line 46 def delete_backup cache.delete backup end |
#digest ⇒ Object
14 15 16 |
# File 'lib/cachext/key.rb', line 14 def digest ::Digest::SHA1.hexdigest ::Marshal.dump(raw) end |
#inspect ⇒ Object
10 11 12 |
# File 'lib/cachext/key.rb', line 10 def inspect "#<Cachext::Key:#{object_id.to_s(16)} @raw=#{@raw.inspect} digest=#{digest}>" end |
#locked? ⇒ Boolean
22 23 24 |
# File 'lib/cachext/key.rb', line 22 def locked? lock_redis.exists digest end |
#read ⇒ Object
26 27 28 |
# File 'lib/cachext/key.rb', line 26 def read cache.read raw end |
#read_backup ⇒ Object
38 39 40 |
# File 'lib/cachext/key.rb', line 38 def read_backup cache.read backup end |
#write(value, options = {}) ⇒ Object
30 31 32 |
# File 'lib/cachext/key.rb', line 30 def write value, = {} cache.write raw, value, end |
#write_backup(value) ⇒ Object
42 43 44 |
# File 'lib/cachext/key.rb', line 42 def write_backup value cache.write backup, value end |