Class: Cachext::Key

Inherits:
Object
  • Object
show all
Defined in:
lib/cachext/key.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#rawObject (readonly)

Returns the value of attribute raw.



3
4
5
# File 'lib/cachext/key.rb', line 3

def raw
  @raw
end

Instance Method Details

#backupObject



18
19
20
# File 'lib/cachext/key.rb', line 18

def backup
  [:backup_cache] + raw
end

#clearObject



34
35
36
# File 'lib/cachext/key.rb', line 34

def clear
  cache.delete raw
end

#delete_backupObject



46
47
48
# File 'lib/cachext/key.rb', line 46

def delete_backup
  cache.delete backup
end

#digestObject



14
15
16
# File 'lib/cachext/key.rb', line 14

def digest
  ::Digest::SHA1.hexdigest ::Marshal.dump(raw)
end

#inspectObject



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

Returns:

  • (Boolean)


22
23
24
# File 'lib/cachext/key.rb', line 22

def locked?
  lock_redis.exists digest
end

#readObject



26
27
28
# File 'lib/cachext/key.rb', line 26

def read
  cache.read raw
end

#read_backupObject



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, options = {}
  cache.write raw, value, options
end

#write_backup(value) ⇒ Object



42
43
44
# File 'lib/cachext/key.rb', line 42

def write_backup value
  cache.write backup, value
end