Parent

Included Modules

Innate::Cache

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.

Attributes

name[R]
instance[R]

Public Class Methods

add(*names) click to toggle source
     # File lib/innate/cache.rb, line 111
111:     def self.add(*names)
112:       names.each{|name| register(new(name)) }
113:     end
new(name, klass = nil) click to toggle source
    # File lib/innate/cache.rb, line 76
76:     def initialize(name, klass = nil)
77:       @name = name.to_s.dup.freeze
78: 
79:       klass ||= options[@name.to_sym]
80:       @instance = klass.new
81: 
82:       @instance.cache_setup(
83:         ENV['HOSTNAME'],
84:         ENV['USER'],
85:         'pristine',
86:         @name
87:       )
88:     end
register(cache) click to toggle source

Add accessors for cache

@param [Cache] cache

     # File lib/innate/cache.rb, line 103
103:     def self.register(cache)
104:       key = cache.name.to_s
105:       return if respond_to?(key) && respond_to?("#{key}=")
106:       (class << self; self; end).send(:attr_accessor, key)
107: 
108:       send("#{key}=", cache)
109:     end
setup() click to toggle source

Add all caches from the options.

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

    # File lib/innate/cache.rb, line 96
96:     def self.setup
97:       options.names.each{|name| add(name) }
98:     end

Public Instance Methods

[](key, default = nil) click to toggle source
Alias for: fetch
[]=(key, value, options = {}) click to toggle source
Alias for: store
clear() click to toggle source
     # File lib/innate/cache.rb, line 115
115:     def clear
116:       instance.cache_clear
117:     end
delete(*keys) click to toggle source
     # File lib/innate/cache.rb, line 119
119:     def delete(*keys)
120:       instance.cache_delete(*keys)
121:     end
fetch(key, default = nil) click to toggle source
     # File lib/innate/cache.rb, line 123
123:     def fetch(key, default = nil)
124:       instance.cache_fetch(key, default)
125:     end
Also aliased as: []
store(key, value, options = {}) click to toggle source
     # File lib/innate/cache.rb, line 128
128:     def store(key, value, options = {})
129:       instance.cache_store(key, value, options)
130:     end
Also aliased as: []=

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.