class Cacheable::CacheAdapters::MemoryAdapter

Attributes

cache[R]

Public Class Methods

new() click to toggle source
# File lib/cacheable/cache_adapters/memory_adapter.rb, line 4
def initialize
  clear
end

Public Instance Methods

clear() click to toggle source
# File lib/cacheable/cache_adapters/memory_adapter.rb, line 33
def clear
  @cache = {}
end
delete(key) click to toggle source
# File lib/cacheable/cache_adapters/memory_adapter.rb, line 26
def delete(key)
  return false unless exist?(key)

  cache.delete key
  true
end
exist?(key) click to toggle source
# File lib/cacheable/cache_adapters/memory_adapter.rb, line 16
def exist?(key)
  cache.key?(key)
end
fetch(key, _options = {}) click to toggle source
# File lib/cacheable/cache_adapters/memory_adapter.rb, line 20
def fetch(key, _options = {})
  return read(key) if exist?(key)

  write(key, Proc.new.call)
end
read(key) click to toggle source
# File lib/cacheable/cache_adapters/memory_adapter.rb, line 8
def read(key)
  cache[key]
end
write(key, value) click to toggle source
# File lib/cacheable/cache_adapters/memory_adapter.rb, line 12
def write(key, value)
  cache[key] = value
end