Class: IpFilter::Cache::DalliStore

Inherits:
IpFilter::Cache show all
Defined in:
lib/ip_filter/cache/dallistore.rb

Instance Attribute Summary

Attributes inherited from IpFilter::Cache

#cached_at, #prefix, #store

Instance Method Summary collapse

Methods inherited from IpFilter::Cache

#initialize, #key_for, #serialize_output

Constructor Details

This class inherits a constructor from IpFilter::Cache

Instance Method Details

#[](ip) ⇒ Object

Read from the Cache.



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/ip_filter/cache/dallistore.rb', line 11

def [](ip)
  result = case
    when store.respond_to?(:read)
      store.read key_for(ip)
    when store.respond_to?(:[])
      store[key_for(ip)]
    when store.respond_to?(:get)
      store.get key_for(ip)
  end
  # this method is inherited from IpFilter::Cache
  serialize_output(result)
end

#[]=(ip, value) ⇒ Object

Write to the Cache.



25
26
27
28
29
30
31
32
33
34
# File 'lib/ip_filter/cache/dallistore.rb', line 25

def []=(ip, value)
  case
    when store.respond_to?(:write)
      store.write key_for(ip), value
    when store.respond_to?(:[]=)
      store[key_for(ip)] = value
    when store.respond_to?(:set)
      store.set key_for(ip), value
  end
end

#resetObject

Clean Cache (not available, as DalliStore cannot iterate on cache)



6
7
8
# File 'lib/ip_filter/cache/dallistore.rb', line 6

def reset
  logger.warning "Cannot reset ip_filter cache with DalliStore, you must reset all your cache manually."
end