Class: Waves::Caches::Simple

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

Overview

This class is more or less here to establish the basic interface for caching and for lightweight caching that doesn’t require a dedicated caching process.

Direct Known Subclasses

File, Memcached

Instance Method Summary collapse

Constructor Details

#initialize(hash = {}) ⇒ Simple

Returns a new instance of Simple.



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

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

Instance Method Details

#[](key) ⇒ Object



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

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

#[]=(key, value) ⇒ Object



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

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

#clearObject



20
# File 'lib/caches/simple.rb', line 20

def clear ; @cache = {} ; end

#delete(key) ⇒ Object



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

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

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

Returns:

  • (Boolean)


15
# File 'lib/caches/simple.rb', line 15

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

#fetch(key) ⇒ Object



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

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

#store(key, val) ⇒ Object



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

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