Skip to content
Snippets Groups Projects
autoexpire_cache.rb 580 B
Newer Older
  • Learn to ignore specific revisions
  • # This class implements a cache with simple delegation to the Redis store, but
    # when it creates a key/value pair, it also sends an EXPIRE command with a TTL.
    # It should be fairly simple to do the same thing with Memcached.
    class AutoexpireCache
      def initialize(store)
        @store = store
        @ttl = 86400
      end
    
      def [](url)
        @store.[](url)
      end
    
      def []=(url, value)
        @store.[]=(url, value)
        @store.expire(url, @ttl)
      end
    
      def keys
        @store.keys
      end
    
      def del(url)
        @store.del(url)
      end
    end
    
    
    Geocoder.configure(:cache => AutoexpireCache.new(Redis.new))