Skip to content

Commit

Permalink
documentation and another test
Browse files Browse the repository at this point in the history
  • Loading branch information
Karl committed May 25, 2011
1 parent 8b94a00 commit d088895
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
13 changes: 13 additions & 0 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Empty file added test/benchmark.rb
Empty file.
6 changes: 6 additions & 0 deletions test/simple_redis_cache_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.