Class: Ramaze::Cache::LRU

Inherits:
Object
  • Object
show all
Includes:
Cache::API
Defined in:
lib/ramaze/cache/lru.rb

Overview

Cache class that uses LRUHash as a storage engine. This cache has the advantage that unlike Innate::Cache::Memory it does not leak memory over time when using the cache for sessions.

Examples:

Ramaze::Cache.options.session = Ramaze::Cache::LRU
Ramaze.setup_dependencies

Author:

  • Michael Fellinger

Since:

  • 17-07-2009

Constant Summary collapse

OPTIONS =

Hash containing all the options for the cache.

Since:

  • 17-07-2009

{
  # expiration in seconds
  :expiration => nil,
  # maximum elements in the cache
  :max_count => 10000,
  # maximum total memory usage of the cache
  :max_total => nil,
  # maximum memory usage of an element of the cache
  :max_value => nil,
}

Instance Method Summary collapse

Instance Method Details

#cache_clearObject

Clears the entire cache.

Author:

  • Michael Fellinger

Since:

  • 17-07-2009



50
51
52
# File 'lib/ramaze/cache/lru.rb', line 50

def cache_clear
  @store.clear
end

#cache_delete(*args) ⇒ Object

Deletes a set of data from the cache

See Also:

  • Innate::Cache::API#cache_delete

Author:

  • Michael Fellinger

Since:

  • 17-07-2009



83
84
85
# File 'lib/ramaze/cache/lru.rb', line 83

def cache_delete(*args)
  super { |key| @store.delete(key) }
end

#cache_fetch(*args) ⇒ Object

Retrieves a set of data from the cache.

See Also:

  • Innate::Cache::API#cache_fetch

Author:

  • Michael Fellinger

Since:

  • 17-07-2009



72
73
74
# File 'lib/ramaze/cache/lru.rb', line 72

def cache_fetch(*args)
  super { |key| @store[key] }
end

#cache_setup(host, user, app, name) ⇒ Object

Prepares the cache by creating a new instance of Ramaze::LRUHash using the options set in OPTIONS.

Author:

  • Michael Fellinger

Since:

  • 17-07-2009



40
41
42
# File 'lib/ramaze/cache/lru.rb', line 40

def cache_setup(host, user, app, name)
  @store = Ramaze::LRUHash.new(OPTIONS)
end

#cache_store(*args) ⇒ Object

Stores a set of data in the cache.

See Also:

  • Innate::Cache::API#cache_store

Author:

  • Michael Fellinger

Since:

  • 17-07-2009



61
62
63
# File 'lib/ramaze/cache/lru.rb', line 61

def cache_store(*args)
  super { |key, value| @store[key] = value }
end