Class: Innate::Cache

### Home Classes Methods

### In Files

- lib/innate/cache.rb
- lib/innate/cache/api.rb
- lib/innate/cache/drb.rb
- lib/innate/cache/file_based.rb
- lib/innate/cache/marshal.rb
- lib/innate/cache/memory.rb
- lib/innate/cache/yaml.rb

### Parent

Object

### Namespace

- MODULE Innate::Cache::API
- MODULE Innate::Cache::FileBased
- CLASS Innate::Cache::DRb
- CLASS Innate::Cache::Marshal
- CLASS Innate::Cache::Memory
- CLASS Innate::Cache::YAML

### Methods

- ::add
- ::new
- ::register
- ::setup
- #[]
- #[]=
- #clear
- #delete
- #fetch
- #store

### Included Modules

- Innate::Optioned

### Class/Module Index

Quicksearch

- Innate
- Innate::Action
- Innate::Adapter
- Innate::Cache
- Innate::Cache::API
- Innate::Cache::DRb
- Innate::Cache::FileBased
- Innate::Cache::Marshal
- Innate::Cache::Memory
- Innate::Cache::YAML
- Innate::Current
- Innate::Etanni
- Innate::Helper
- Innate::Helper::Aspect
- Innate::Helper::Aspect::SingletonMethods
- Innate::Helper::CGI
- Innate::Helper::Flash
- Innate::Helper::Link
- Innate::Helper::Redirect
- Innate::Helper::Render
- Innate::HelperAccess
- Innate::HelpersHelper
- Innate::LRUHash
- Innate::LogHub
- Innate::Mock
- Innate::Mock::Session
- Innate::Node
- Innate::Optioned
- Innate::Optioned::SingletonMethods
- Innate::Options
- Innate::Request
- Innate::Response
- Innate::Rewrite
- Innate::Route
- Innate::Session
- Innate::Session::Flash
- Innate::SingletonMethods
- Innate::StateAccessor
- Innate::Traited
- Innate::Trinity
- Innate::URLMap
- Innate::View
- Innate::View::ERB
- Innate::View::Etanni
- Innate::View::None
- Logger
- Logger::ColorFormatter
- Object

No matching classes.

# 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

instance[R]
name[R]

### Public Class Methods

add(*names) click to toggle source

    # File lib/innate/cache.rb, line 111
    def self.add(*names)
      names.each{|name| register(new(name)) }
    end

new(name, klass = nil) click to toggle source

    # File lib/innate/cache.rb, line 76
    def initialize(name, klass = nil)
      @name = name.to_s.dup.freeze

      klass ||= options[@name.to_sym]
      @instance = klass.new

      @instance.cache_setup(
        ENV['HOSTNAME'],
        ENV['USER'],
        'pristine',
        @name
      )
    end

register(cache) click to toggle source

Add accessors for cache

@param [Cache] cache

    # File lib/innate/cache.rb, line 103
    def self.register(cache)
      key = cache.name.to_s
      return if respond_to?(key) && respond_to?("#{key}=")
      (class << self; self; end).send(:attr_accessor, key)

      send("#{key}=", cache)
    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
    def self.setup
      options.names.each{|name| add(name) }
    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
    def clear
      instance.cache_clear
    end

delete(*keys) click to toggle source

    # File lib/innate/cache.rb, line 119
    def delete(*keys)
      instance.cache_delete(*keys)
    end

fetch(key, default = nil) click to toggle source

    # File lib/innate/cache.rb, line 123
    def fetch(key, default = nil)
      instance.cache_fetch(key, default)
    end

Also aliased as: []
store(key, value, options = {}) click to toggle source

    # File lib/innate/cache.rb, line 128
    def store(key, value, options = {})
      instance.cache_store(key, value, options)
    end

Also aliased as: []=

[Validate]

Generated with the Darkfish Rdoc Generator 2.