Class: Waves::Caches::Simple

Inherits:
Object
  • Object
show all
Defined in:
lib/waves/caches/simple.rb

Overview

A simple in-memory cache. This also serves as the base class for all the Waves caching implementations, so that descendents only need to override #initialize, #fetch, #store, #delete, and #clear, since the other methods are defined in terms of those.

Direct Known Subclasses

File, Memcached

Instance Method Summary collapse

Constructor Details

#initialize(hash = {}) ⇒ Simple

Returns a new instance of Simple.



11
# File 'lib/waves/caches/simple.rb', line 11

def initialize( hash = {} ) ; @cache = hash ; end

Instance Method Details

#[](key) ⇒ Object



12
# File 'lib/waves/caches/simple.rb', line 12

def [](key) ; fetch(key) ; end

#[]=(key, value) ⇒ Object



13
# File 'lib/waves/caches/simple.rb', line 13

def []=( key, value ) ; store( key, value ) ; end

#clearObject



19
# File 'lib/waves/caches/simple.rb', line 19

def clear ; @cache = {} ; end

#delete(key) ⇒ Object



18
# File 'lib/waves/caches/simple.rb', line 18

def delete( key ) ; @cache.delete( key ) ; end

#exists?(key) ⇒ Boolean Also known as: exist?

Returns:

  • (Boolean)


14
# File 'lib/waves/caches/simple.rb', line 14

def exists?( key ) ; fetch(key) == nil ? false : true ; end

#fetch(key) ⇒ Object



17
# File 'lib/waves/caches/simple.rb', line 17

def fetch( key ) ; @cache[ key ] ; end

#store(key, val) ⇒ Object



16
# File 'lib/waves/caches/simple.rb', line 16

def store( key, val ) ; @cache[ key ] = val ; end