Class: IpFilter::Cache

Inherits:
Object
  • Object
show all
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

DalliStore, Redis

Defined Under Namespace

Classes: DalliStore, Redis

Instance Attribute Summary collapse

Instance Method Summary collapse

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_atObject (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

#prefixObject (readonly)

Returns the value of attribute prefix.



9
10
11
# File 'lib/ip_filter/cache.rb', line 9

def prefix
  @prefix
end

#storeObject (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