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:

Since:

Constant Summary

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

- (Object) cache_clear

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

- (Object) cache_delete(*args)

Deletes a set of data from the cache

See Also:

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

- (Object) cache_fetch(*args)

Retrieves a set of data from the cache.

See Also:

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

- (Object) cache_setup(host, user, app, name)

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

- (Object) cache_store(*args)

Stores a set of data in the cache.

See Also:

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