Class: IpFilter::Cache
- Inherits:
-
Object
- Object
- IpFilter::Cache
- Defined in:
- lib/ip_filter/cache.rb,
lib/ip_filter/cache/redis.rb,
lib/ip_filter/cache/dallistore.rb
Overview
For now just a simple wrapper class for a Memcache client.
Direct Known Subclasses
Defined Under Namespace
Classes: DalliStore, Redis
Instance Attribute Summary collapse
-
#cached_at ⇒ Object
readonly
Returns the value of attribute cached_at.
-
#prefix ⇒ Object
readonly
Returns the value of attribute prefix.
-
#store ⇒ Object
readonly
Returns the value of attribute store.
Instance Method Summary collapse
-
#initialize(store, prefix = IpFilter.configuration.cache_prefix) ⇒ Cache
constructor
A new instance of Cache.
-
#key_for(ip) ⇒ Object
Cache key for a given URL.
- #serialize_output(value) ⇒ Object
Constructor Details
#initialize(store, prefix = IpFilter.configuration.cache_prefix) ⇒ Cache
Returns a new instance of Cache.
11 12 13 14 15 |
# File 'lib/ip_filter/cache.rb', line 11 def initialize(store, prefix = IpFilter.configuration.cache_prefix) @store = store @prefix = prefix @cached_at ||= DateTime.now end |
Instance Attribute Details
#cached_at ⇒ Object (readonly)
Returns the value of attribute cached_at.
8 9 10 |
# File 'lib/ip_filter/cache.rb', line 8 def cached_at @cached_at end |
#prefix ⇒ Object (readonly)
Returns the value of attribute prefix.
9 10 11 |
# File 'lib/ip_filter/cache.rb', line 9 def prefix @prefix end |
#store ⇒ Object (readonly)
Returns the value of attribute store.
9 10 11 |
# File 'lib/ip_filter/cache.rb', line 9 def store @store end |
Instance Method Details
#key_for(ip) ⇒ Object
Cache key for a given URL.
26 27 28 |
# File 'lib/ip_filter/cache.rb', line 26 def key_for(ip) [prefix, ip].join end |
#serialize_output(value) ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/ip_filter/cache.rb', line 17 def serialize_output(value) if !value.nil? && value != 'null' value = JSON.parse(value) if value.is_a? String return OpenStruct.new(value) end return nil end |