Module: Venduitz::Cache

Defined in:
lib/venduitz/cache.rb

Overview

Module responsible for creating an interface for the different cache storages

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.configObject

Config



74
75
76
# File 'lib/venduitz/cache.rb', line 74

def config
  @config
end

.digestorObject

Returns the value of attribute digestor.



9
10
11
# File 'lib/venduitz/cache.rb', line 9

def digestor
  @digestor
end

.driverObject

Returns the value of attribute driver.



9
10
11
# File 'lib/venduitz/cache.rb', line 9

def driver
  @driver
end

.enabledObject

Returns the value of attribute enabled.



9
10
11
# File 'lib/venduitz/cache.rb', line 9

def enabled
  @enabled
end

.namespaceObject

Get the namespace



69
70
71
# File 'lib/venduitz/cache.rb', line 69

def namespace
  @namespace
end

Class Method Details

.clear(opts = nil) ⇒ Object

Clear the full cache

Parameters:

  • opts (Hash) (defaults to: nil)

    Options to use while clear the cache



59
60
61
# File 'lib/venduitz/cache.rb', line 59

def clear(opts = nil)
  _driver.clear(opts)
end

.digest(object) ⇒ Object

Digest



20
21
22
23
24
25
26
27
28
29
# File 'lib/venduitz/cache.rb', line 20

def digest(object)
  # The dumped data
  dump = Marshal::dump(object)

  # Check if the digestor is empty
  digestor = Digest::MD5 if digestor.nil?

  # Digest it
  digestor.hexdigest dump
end

.exist?(key) ⇒ Boolean

Check if the key exists

Returns:

  • (Boolean)


32
33
34
# File 'lib/venduitz/cache.rb', line 32

def exist?(key)
  _driver.exist?(key)
end

.get(key) ⇒ Object

Get the key



37
38
39
40
# File 'lib/venduitz/cache.rb', line 37

def get(key)
  # Using the driver itself
  _driver.get(key)
end

.namespace?Boolean

Check if there is namespace

Returns:

  • (Boolean)


64
65
66
# File 'lib/venduitz/cache.rb', line 64

def namespace?
  !@namespace.nil?
end

.set(key, value, dump = true, options = {}) ⇒ Object

Set the cache

Parameters:

  • key (Any)

    The key used on the cache

  • dump (Boolean) (defaults to: true)

    If is necessary to dump the Key

  • value (Any)

    The value of the cache



46
47
48
49
50
51
52
53
54
55
# File 'lib/venduitz/cache.rb', line 46

def set(key, value, dump = true, options = {})
  #
  key = digest(key) if dump

  # If the driver has any namespace method or fixed value
  key = "#{namespace}/#{key}" if namespace?

  #
  _driver.set(key, value, options)
end