Class: ActiveAcl::Cache::MemcacheAdapter

Inherits:
Object
  • Object
show all
Defined in:
lib/active_acl/cache/memcache_adapter.rb

Overview

This is a cache adapter for the second level cache using the memcache daemon (www.danga.com/memcached). Sets itself as the cache adapter if the source file is loaded so a simple require is enough to activate the memcache. Before using the memcache, make sure to set MemcacheAdapter.cache.

In environment.rb:

require 'active_acl/cache/memcache_adapter'
ActiveAcl::Cache::MemcacheAdapter.cache = MemCache.new('localhost:11211', :namespace => 'my_namespace')

you can also set the time to leave:

ActiveAcl::OPTIONS[:cache_privilege_timeout]= time_in_seconds

Detailed instructions on how to set up the server can be found at dev.robotcoop.com/Libraries/memcache-client.

Class Method Summary collapse

Class Method Details

.cacheObject

returns the memcache server



16
17
18
# File 'lib/active_acl/cache/memcache_adapter.rb', line 16

def self.cache #:nodoc:
  @@cache
end

.cache=(cache) ⇒ Object

sets the memcache server



21
22
23
# File 'lib/active_acl/cache/memcache_adapter.rb', line 21

def self.cache=(cache) #:nodoc:
  @@cache = cache
end

.delete(key) ⇒ Object

purge data from cache.



40
41
42
43
# File 'lib/active_acl/cache/memcache_adapter.rb', line 40

def self.delete(key) #:nodoc:
  @@cache.delete(key)
  Rails.logger.debug 'GACL::SECOND_LEVEL_CACHE::DELETE ' + key.to_s    
end

.get(key) ⇒ Object

get a value from the cache



26
27
28
29
30
# File 'lib/active_acl/cache/memcache_adapter.rb', line 26

def self.get(key) #:nodoc:
  value = @@cache.get(key)
  Rails.logger.debug 'GACL::SECOND_LEVEL_CACHE::' + (value.nil? ? 'MISS ' : 'HIT ')+ key.to_s
  value
end

.set(key, value, ttl) ⇒ Object

set a value to the cache, specifying the time to live (ttl). Set ttl to 0 for unlimited.



34
35
36
37
# File 'lib/active_acl/cache/memcache_adapter.rb', line 34

def self.set(key, value, ttl) #:nodoc:
  @@cache.set(key, value, ttl)
  Rails.logger.debug 'GACL::SECOND_LEVEL_CACHE::SET ' + key.to_s + ' TO ' + value.inspect.to_s + ' TTL ' + ttl.to_s    
end