Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reshuffles the placement of the Merb::Cache methods
- Loading branch information
Daniel Neighman
committed
Jun 22, 2008
1 parent
ca7b9e4
commit 177a0b2
Showing
5 changed files
with
79 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,57 @@ | ||
# Require components | ||
require 'merb-cache/controller' | ||
require 'merb-cache/cache_store' | ||
module Merb | ||
module Cache | ||
class << self | ||
# Addess to registered stores | ||
# name<Symbol> : The Name of the store type | ||
# value<Hash> : Requires a hash with to describe the cache. See Merb::Cache.register | ||
def [](name) | ||
active_stores | ||
@active_stores[name] | ||
end | ||
|
||
path = File.expand_path(File.join(File.dirname(__FILE__))) | ||
Merb::Cache.register(:memcached, :path => (path / "cache_stores" / "memcached_store"), :class_name => "MemcachedStore") | ||
Merb::Cache.register(:mintcache, :path => (path / "cache_stores" / "mintcache_store"), :class_name => "MintcachedStore") | ||
|
||
|
||
Merb::BootLoader.before_app_loads do | ||
# require code that must be loaded before the application | ||
end | ||
|
||
Merb::BootLoader.after_app_loads do | ||
# code that can be required after the application loads | ||
# Initialize the cache store if there is not one setup for the default | ||
Merb::Cache.setup(:default, :memcached) if Merb::Cache[:default].empty? | ||
end | ||
# Register a cache store with Merb::Cache | ||
# name<Symbol> : A label for the cache store | ||
# options<Hash>: A hash of options | ||
# Required Options | ||
# :path => "path/to/cache/store" | ||
# :class_name => "ClassNameOfStore" | ||
def register(name, options = {}) | ||
raise ArgumentError, "Requires :path and :class_name options" unless ([:path, :class_name] - options.keys).empty? | ||
raise Merb::Cache::Store::NotFound, "Missing Store File: #{options[:path]}" unless File.exists?("#{options[:path]}.rb") | ||
@registered_stores ||= Hash.new{|h,k| h[k] = {}} | ||
@registered_stores[name.to_sym] = options | ||
end | ||
|
||
# Sets up a cache store | ||
# name<Symbol> : A label or name to give the cache | ||
# store<Symbol> : A registered store type. By default :memcached, and :mintstore are supported | ||
# opts<Hash> : A hash to pass through to the store for configuration | ||
def setup(name, store, opts = {}) | ||
active_stores | ||
load_store(store) | ||
@active_stores[name] = self.const_get(registered_stores[store.to_sym][:class_name]).new(opts) | ||
end | ||
|
||
# === Returns | ||
# A Hash of registered store types | ||
def registered_stores | ||
@registered_stores || Hash.new{|h,k| h[k] = {}} | ||
end | ||
|
||
# Returns a Hash of active stores. | ||
def active_stores | ||
@active_stores ||= {} | ||
end | ||
|
||
protected | ||
def []=(name,value) | ||
@active_stores[name] = value | ||
end | ||
|
||
def load_store(store) | ||
require registered_stores[store.to_sym][:path] rescue raise Store::NotFound.new(store) | ||
end | ||
end # # << self | ||
end # Cache | ||
end # Merb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,6 @@ | |
:fail => 'badconfigoptions' | ||
} | ||
|
||
|
||
end | ||
end | ||
|
||
|