aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test/caching_test.rb
diff options
context:
space:
mode:
authorDaniel Schierbeck <dasch@zendesk.com>2013-04-15 16:41:27 +0200
committerDaniel Schierbeck <dasch@zendesk.com>2013-05-06 11:38:51 +0200
commit36d41a15c35e6f4b698931987b2115e221d0fcfa (patch)
tree14855f1938c45adfb6a64511107ead949ab1fde1 /activesupport/test/caching_test.rb
parent6023a5049172e2222181881679b56c0e29034c96 (diff)
downloadrails-36d41a15c35e6f4b698931987b2115e221d0fcfa.tar.gz
rails-36d41a15c35e6f4b698931987b2115e221d0fcfa.tar.bz2
rails-36d41a15c35e6f4b698931987b2115e221d0fcfa.zip
Allow fetching multiple values from the cache at once
Add a simple API for fetching a list of entries from the cache, where any missing entries are computed by a supplied block.
Diffstat (limited to 'activesupport/test/caching_test.rb')
-rw-r--r--activesupport/test/caching_test.rb20
1 files changed, 20 insertions, 0 deletions
diff --git a/activesupport/test/caching_test.rb b/activesupport/test/caching_test.rb
index bcc200cf33..ae6eaa4b60 100644
--- a/activesupport/test/caching_test.rb
+++ b/activesupport/test/caching_test.rb
@@ -257,6 +257,26 @@ module CacheStoreBehavior
assert_equal({"fu" => "baz"}, @cache.read_multi('foo', 'fu'))
end
+ def test_fetch_multi
+ @cache.write('foo', 'bar')
+ @cache.write('fud', 'biz')
+
+ values = @cache.fetch_multi('foo', 'fu', 'fud') {|value| value * 2 }
+
+ assert_equal(["bar", "fufu", "biz"], values)
+ assert_equal("fufu", @cache.read('fu'))
+ end
+
+ def test_multi_with_objects
+ foo = stub(:title => "FOO!", :cache_key => "foo")
+ bar = stub(:cache_key => "bar")
+
+ @cache.write('bar', "BAM!")
+
+ values = @cache.fetch_multi(foo, bar) {|object| object.title }
+ assert_equal(["FOO!", "BAM!"], values)
+ end
+
def test_read_and_write_compressed_small_data
@cache.write('foo', 'bar', :compress => true)
assert_equal 'bar', @cache.read('foo')