Class: Ramaze::Cache::LRU

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

Overview

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

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



46
47
48
# File 'lib/ramaze/cache/lru.rb', line 46

def cache_clear
  @store.clear
end

- (Object) cache_delete(*args)

Deletes a set of data from the cache

See Also:

  • Innate::Cache::API#cache_delete

Author:

  • Michael Fellinger

Since:

  • 17-07-2009



79
80
81
# File 'lib/ramaze/cache/lru.rb', line 79

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

- (Object) cache_fetch(*args)

Retrieves a set of data from the cache.

See Also:

  • Innate::Cache::API#cache_fetch

Author:

  • Michael Fellinger

Since:

  • 17-07-2009



68
69
70
# File 'lib/ramaze/cache/lru.rb', line 68

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 Ramaze::Cache::LRU::OPTIONS.

Author:

  • Michael Fellinger

Since:

  • 17-07-2009



36
37
38
# File 'lib/ramaze/cache/lru.rb', line 36

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:

  • Innate::Cache::API#cache_store

Author:

  • Michael Fellinger

Since:

  • 17-07-2009



57
58
59
# File 'lib/ramaze/cache/lru.rb', line 57

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