Module: Rimcache

Defined in:
lib/rimcache.rb,
lib/rimcache/store.rb,
lib/rimcache/config.rb,
lib/rimcache/version.rb

Overview

The main entry point to Rimcache. “Caches” commonly-used objects by just storing them frozen in a global hash. Expiration is handled via Rails low-level caching or a configurable ActiveSupport::Cache::Store.

Defined Under Namespace

Classes: Config, Store

Constant Summary collapse

VERSION =
"0.1.0"

Class Method Summary collapse

Class Method Details

.configObject

The Rimcache::Config object associated with the singleton store



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

def self.config
  store.config
end

.expireObject



34
35
36
# File 'lib/rimcache.rb', line 34

def self.expire(...)
  store.expire(...)
end

.fetchObject

Fetches or updates data from the rimcache at the given key. If there’s an unexpired stored value it is returned. Otherwise, the block is called and the result is frozen, stored in the rimcache under this key, and returned.

The keyword argument for_update can be set to true to call the block and return the result unfrozen instead of caching it. You must still call expire(key) or update(key, value) after updating the record in the database.



30
31
32
# File 'lib/rimcache.rb', line 30

def self.fetch(...)
  store.fetch(...)
end

.rimcacheObject

You can include Rimcache in your model to use rimcache instead of Rimcache.fetch



41
42
43
# File 'lib/rimcache.rb', line 41

def rimcache(...)
  Rimcache.fetch(...)
end

.rimcache_expireObject

You can include Rimcache in your model to use rimcache_expire instead of Rimcache.expire



46
47
48
# File 'lib/rimcache.rb', line 46

def rimcache_expire(...)
  Rimcache.expire(...)
end

.storeObject

A singleton instance of Rimcache::Store.



12
13
14
# File 'lib/rimcache.rb', line 12

def self.store
  @store ||= Store.include(Singleton).instance
end