Class Innate::Cache
In: lib/innate/cache.rb
lib/innate/cache/file_based.rb
lib/innate/cache/marshal.rb
lib/innate/cache/yaml.rb
lib/innate/cache/memory.rb
lib/innate/cache/api.rb
lib/innate/cache/drb.rb
Parent: Object

Cache manager and wrapper.

Provides a convenient wrapper around caches to keep method name confusion at a minimum while still having short and meaningful method names for every cache instance.

The default caching is specified in lib/innate.rb in the config section. At the time of writing it defaults to Innate::Cache::Memory but can be changed easily.

Configuration has to be done before Innate::setup_dependencies is being called.

Configuration:

  Innate::Cache.options do |cache|
    cache.names = [:session, :user]
    cache.session = Innate::Cache::Marshal
    cache.user = Innate::Cache::YAML
  end

Usage for storing:

  # Storing with a time to live (10 seconds)
  Innate::Cache.user.store(:manveru, "Michael Fellinger", :ttl => 10)

  # Storing indefinitely
  Innate::Cache.user[:Pistos] = "unknown"
  # or without :ttl argument
  Innate::Cache.user.store(:Pistos, "unknown")

Usage for retrieving:

  # we stored this one for 10 seconds
  Innate::Cache.user.fetch(:manveru, 'not here anymore')
  # => "Michael Fellinger"
  sleep 11
  Innate::Cache.user.fetch(:manveru, 'not here anymore')
  # => "not here anymore"

  Innate::Cache.user[:Pistos]
  # => "unknown"
  Innate::Cache.user.fetch(:Pistos)
  # => "unknown"

For more details and to find out how to implement your own cache please read the documentation of Innate::Cache::API

NOTE:

  * Some caches might expose their contents for everyone else on the same
    system, or even on connected systems. The rule as usual is, not to
    cache sensitive information.

Methods

[]   []=   add   clear   delete   fetch   new   register   setup   store  

Included Modules

Optioned

Classes and Modules

Module Innate::Cache::API
Module Innate::Cache::FileBased
Class Innate::Cache::DRb
Class Innate::Cache::Marshal
Class Innate::Cache::Memory
Class Innate::Cache::YAML

Attributes

instance  [R] 
name  [R] 

Public Class methods

Add accessors for cache

@param [Cache] cache

Add all caches from the options.

@see Innate::setup_dependencies @api stable @return [Array] names of caches initialized @author manveru

Public Instance methods

[](key, default = nil)

Alias for fetch

[]=(key, value, options = {})

Alias for store

[Validate]