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.



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

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

Instance Attribute Details

#storageObject

Returns the value of attribute storage.



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

def storage
  @storage
end

Instance Method Details

#clearObject



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

def clear
  initialize
end

#delete(key) ⇒ Object

Parameters:

  • key (String)


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

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

#get(key) ⇒ Object

Parameters:

  • key (String)

Returns:

  • (Object)


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

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

#set(key, value) ⇒ Object

Parameters:

  • key (String)
  • value (Object)


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

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