Sha256: 7c0729d7fdea39c71c1ebbb9ff2cc42d8306324ca87bf057738ea696069cb512

Contents?: true

Size: 1.19 KB

Versions: 12

Compression:

Stored size: 1.19 KB

Contents

module Amfetamine
  # This adapter wraps methods around memcached (dalli) methods
  module CachingAdapter
    def self.included(base)
      base.extend ClassAndInstanceMethods
      base.extend CacheServer
      base.send(:include,ClassAndInstanceMethods)
    end


    def initialize(server, options={})
      @cache_server ||= Dalli::Client.new(server, options)
    end

    def cache_server
      @cache_server
    end

    private :cache_server

    module ClassAndInstanceMethods
      def get(key)
        cache_server.get(key)
      end

      def set(key,data)
        cache_server.set(key, data)
      end

      def add(key, data)
        cache_server.add(key,data)
      end

      def delete(key)
        cache_server.delete(key)
      end

      def flush
        cache_server.flush
      end

      def fetch(key)
        #cache_server.fetch(key,&block)
        val = get(key)
        if val.nil? && block_given?
          val = yield
          add(key,val)
        else
          Amfetamine.logger.info "Hit! #{key}"
        end
        val
      end
    end

    module CacheServer
      private
      def cache_server
        Amfetamine::Config.memcached_instance
      end

  

    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
amfetamine-0.3.0 lib/amfetamine/caching_adapter.rb
amfetamine-0.2.12 lib/amfetamine/caching_adapter.rb
amfetamine-0.2.11 lib/amfetamine/caching_adapter.rb
amfetamine-0.2.9 lib/amfetamine/caching_adapter.rb
amfetamine-0.2.7 lib/amfetamine/caching_adapter.rb
amfetamine-0.2.6 lib/amfetamine/caching_adapter.rb
amfetamine-0.2.5 lib/amfetamine/caching_adapter.rb
amfetamine-0.2.4 lib/amfetamine/caching_adapter.rb
amfetamine-0.2.3 lib/amfetamine/caching_adapter.rb
amfetamine-0.2.1 lib/amfetamine/caching_adapter.rb
amfetamine-0.2.0 lib/amfetamine/caching_adapter.rb
amfetamine-0.1.5 lib/amfetamine/caching_adapter.rb