Sha256: c5c076f8e2f79478c2a1820dfb15ee96f69132fe0c758115d575b1f764ebce55

Contents?: true

Size: 1.42 KB

Versions: 1

Compression:

Stored size: 1.42 KB

Contents

#          Copyright (c) 2006 Michael Fellinger m.fellinger@gmail.com
# All files in this distribution are subject to the terms of the Ruby license.

require 'ramaze/cache/memory'

module Ramaze
  autoload :YAMLStoreCache, "ramaze/cache/yaml_store.rb"
  autoload :MemcachedCache, "ramaze/cache/memcached.rb"

  # This is the wrapper of all caches, providing mechanism
  # for switching caching from one adapter to another.

  class Cache
    include Enumerable
    CACHES = {} unless defined?(CACHES)

    class << self

      def startup(options)
        Cache.add :compiled, :actions, :patterns, :resolved, :shield
      end

      # This will define a method to access a new cache directly over
      # sinleton-methods on Cache

      def add *keys
        keys.each do |key|
          CACHES[key] = new
          self.class.class_eval do
            define_method(key){ CACHES[key] }
          end
        end
        Inform.debug("Added caches for: #{keys.join(', ')}")
      end

    end

    def initialize(cache = Global.cache)
      @cache = cache.new
    end

    def [](key)
      @cache[key.to_s]
    end

    def []=(key, value)
      @cache[key.to_s] = value
    end

    def delete(*args)
      args.each do |arg|
        @cache.delete(arg.to_s)
      end
    end

    def method_missing(meth, *args, &block)
      if @cache.respond_to?(meth)
        @cache.send(meth, *args, &block)
      else
        super
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ramaze-0.1.2 lib/ramaze/cache.rb