README.md in object-cache-0.0.1 vs README.md in object-cache-0.0.2
- old
+ new
@@ -81,23 +81,35 @@
By default, a cached object has a `ttl` (time to live) of one week. This means
that every request after the first request uses the value from the cached
object. After one week, the cached value becomes stale, and the first request
after that will again store the (possibly changed) object in the cache store.
-You can easily modify the `ttl` using the keyword argument by that same name:
+You can globaly set the default ttl to a different value:
```ruby
+Cache.default_ttl = 120
+```
+
+You can easily modify the `ttl` per cached object, using the keyword argument by
+that same name:
+
+```ruby
Cache.new(ttl: 60) { 'remember me for 60 seconds!' }
```
Or, if you want the cached object to never go stale, disable the TTL entirely:
```ruby
Cache.new(ttl: nil) { 'I am forever in your cache!' }
Cache.new(ttl: 0) { 'me too!' }
```
+Note that it is best to never leave a value in the backend forever. Since this
+library uses file names and line numbers to store the value, a change in your
+code might mean a new cache object is created after a deployment, and your old
+cache object becomes orphaned, and will polute your storage forever.
+
#### namespaced keys
When storing the key/value object into Redis, the key name is based on the file
name and line number where the cache was initiated. This allows you to cache
objects without specifying any namespacing yourself.
@@ -134,10 +146,13 @@
```ruby
Cache.backend = { primary: Redis.new, replicas: [Redis.new, Redis.new] }
```
+When writing the initial object to the backend, the `primary` Redis is used. On
+subsequent requests, a random replica is used to retrieve the stored value.
+
The above example obiously only works if the replicas receive the written data
from the primary instance.
#### core extension
@@ -148,9 +163,18 @@
require 'object/cache/core_extension'
# these are the same:
cache('hello', ttl: 60) { 'hello world' }
Cache.new('hello', ttl: 60) { 'hello world' }
+```
+
+Since the core extension adds the `cache` method to the `Object` class, you can
+also call this method directly on any instances inheriting from `Object`:
+
+```ruby
+require 'object/cache/core_extension'
+
+'hello world'.cache(ttl: 60)
```
That's it!
## License