Permalink
Browse files

documentation and another test

  • Loading branch information...
1 parent 8b94a00 commit d0888953bc7e30b38aaad22c3a5a950f034ca412 Karl committed May 25, 2011
Showing with 19 additions and 0 deletions.
  1. +13 −0 README.markdown
  2. 0 test/benchmark.rb
  3. +6 −0 test/simple_redis_cache_test.rb
View
@@ -22,6 +22,19 @@ Call it straight from the module instead and this time cache it forever.
SimpleRedisCache.cache('hello') { 'world' }
```
+Maybe we should cache something worth while. If the result of the block is not a string, make sure to convert it to one.
+
+```ruby
+ require 'json'
+
+ JSON.parse(cache('20_perm_4', :ttl=>120){ (0..20).to_a.permutation(4).to_a.to_json })
+```
+
+Notice we serialize to json inside the block and from json outside the block. Of course converting an enormous array
+to and from JSON is slower than the permutation so maybe it's not the best example. Replace the above with an expensive
+databse calculation and it makes more sense.
+
+
The above uses the default _Redis.new_ instance running on _127.0.0.1:6379_
Let's configure a different redis instance.
View
No changes.
@@ -48,5 +48,11 @@ def test_cache_on_module_method
assert_equal(redis['hello'], 'world')
end
+ require 'json'
+ def test_cache_permutations
+ assert_equal( (0..20).to_a.permutation(3).to_a, JSON.parse(cache('20_perm_4'){ (0..20).to_a.permutation(3).to_a.to_json }) )
+ end
+
+
end

0 comments on commit d088895

Please sign in to comment.