Class: Handlers::Handler
- Inherits:
-
Object
- Object
- Handlers::Handler
- Defined in:
- lib/handlers/handlers.rb
Overview
creating a new cache handler is as simple as extending from the handler class, setting the class to use as the cache by calling cache_class(“Redis”) and then implementing the increment and get methods for that cache type.
If you don’t want to extend from Handler you can just create a class that implements increment(key), get(key) and handles?(info)
you can then initialize the middleware and pass :cache=>CACHE_NAME as an option.
Direct Known Subclasses
ActiveSupportCacheStoreHandler, HashHandler, MemCacheHandler, RedisHandler
Class Method Summary collapse
Instance Method Summary collapse
- #get(key) ⇒ Object
- #increment(key) ⇒ Object
-
#initialize(object = nil) ⇒ Handler
constructor
A new instance of Handler.
Constructor Details
#initialize(object = nil) ⇒ Handler
Returns a new instance of Handler.
21 22 23 24 |
# File 'lib/handlers/handlers.rb', line 21 def initialize(object=nil) cache = Object.const_get(self.class.cache_class) @cache = object.is_a?(cache) ? object : cache.new end |
Class Method Details
.cache_class(name = nil) ⇒ Object
36 37 38 39 |
# File 'lib/handlers/handlers.rb', line 36 def cache_class(name = nil) @cache_class = name if name @cache_class end |
Instance Method Details
#get(key) ⇒ Object
30 31 32 |
# File 'lib/handlers/handlers.rb', line 30 def get(key) raise "Cache Handlers must implement a get method" end |
#increment(key) ⇒ Object
26 27 28 |
# File 'lib/handlers/handlers.rb', line 26 def increment(key) raise "Cache Handlers must implement an increment method" end |