Class: MMS::Cache

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/mms/cache.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCache

Returns a new instance of Cache.



10
11
12
# File 'lib/mms/cache.rb', line 10

def initialize
  @storage = Hash.new { |hash, key| hash[key] = nil }
end

Instance Attribute Details

#storageObject

Returns the value of attribute storage.



7
8
9
# File 'lib/mms/cache.rb', line 7

def storage
  @storage
end

Instance Method Details

#clearObject



31
32
33
# File 'lib/mms/cache.rb', line 31

def clear
  initialize
end

#delete(key) ⇒ Object

Parameters:

  • key (String)


27
28
29
# File 'lib/mms/cache.rb', line 27

def delete(key)
  @storage.delete key unless @storage[key].nil?
end

#get(key) ⇒ Object

Parameters:

  • key (String)

Returns:

  • (Object)


22
23
24
# File 'lib/mms/cache.rb', line 22

def get(key)
  @storage[key].nil? ? nil : @storage[key]
end

#set(key, value) ⇒ Object

Parameters:

  • key (String)
  • value (Object)


16
17
18
# File 'lib/mms/cache.rb', line 16

def set(key, value)
  @storage[key] = value
end