Browse files

default to a memory store

  • Loading branch information...
1 parent 151404a commit bdc4b4c7550efbd961736a13276bcfa59144b380 @seamusabshere committed Feb 24, 2011
Showing with 29 additions and 7 deletions.
  1. +1 −1 cache_method.gemspec
  2. +5 −5 lib/cache_method/config.rb
  3. +1 −1 lib/cache_method/version.rb
  4. +22 −0 test/test_cache_method.rb
View
2 cache_method.gemspec
@@ -18,7 +18,7 @@ Gem::Specification.new do |s|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
s.require_paths = ["lib"]
- s.add_dependency 'cache'
+ s.add_dependency 'cache', '>=0.1.2'
s.add_development_dependency 'memcached'
# if RUBY_VERSION >= '1.9'
# s.add_development_dependency 'ruby-debug19'
View
10 lib/cache_method/config.rb
@@ -25,16 +25,16 @@ class Config
#
# Example:
# CacheMethod.config.storage = Memcached.new '127.0.0.1:11211'
- def storage=(raw_client)
- if raw_client.is_a?(::Cache)
- @storage = raw_client
+ def storage=(raw_client_or_nil)
+ if raw_client_or_nil.is_a?(::Cache)
+ @storage = raw_client_or_nil
else
- @storage = ::Cache.new raw_client
+ @storage = ::Cache.new raw_client_or_nil
end
end
def storage #:nodoc:
- @storage || raise("You need to set CacheMethod.config.storage with a cache storage of your choice")
+ @storage ||= ::Cache.new
end
# TTL for method caches. Defaults to 24 hours or 86,400 seconds.
View
2 lib/cache_method/version.rb
@@ -1,3 +1,3 @@
module CacheMethod
- VERSION = "0.1.2"
+ VERSION = "0.1.3"
end
View
22 test/test_cache_method.rb
@@ -196,4 +196,26 @@ def test_clear_correct_class_method
assert_equal 'danke schoen', Blog2.get_latest_entries
assert_equal 2, Blog2.request_count
end
+
+ def test_never_set_storage
+ CacheMethod.config.instance_variable_set :@storage, nil
+ a = CopyCat1.new 'mimo'
+
+ assert_equal 'hi', a.echo('hi')
+ assert_equal 1, a.echo_count
+
+ assert_equal 'hi', a.echo('hi')
+ assert_equal 1, a.echo_count
+ end
+
+ def test_set_storage_to_nil
+ CacheMethod.config.storage = nil
+ a = CopyCat1.new 'mimo'
+
+ assert_equal 'hi', a.echo('hi')
+ assert_equal 1, a.echo_count
+
+ assert_equal 'hi', a.echo('hi')
+ assert_equal 1, a.echo_count
+ end
end

0 comments on commit bdc4b4c

Please sign in to comment.