memcacheable 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +5 -5
- data/lib/memcacheable/fetcher.rb +1 -2
- data/lib/memcacheable/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8ada7260a91b22ee55210e38fced1ee123e23c2e
|
4
|
+
data.tar.gz: 86e4b7113bc21f837d3b17261b6bf00f589db6b0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 64ab2b3303b5f27c66eef23cfe426ccc98d925995cdcc20ba631e4348d6bad53319aca7c8b311cc85a82b2fa60f76582f368579d08f2f2241e75a5a25538ea51
|
7
|
+
data.tar.gz: 15c657ebc23dc4b4807423d5e0c317709cf9005ad675c9030e601f0bd86e52d834eeaa37804c1fd4c158749d49b676366ca24833b14f0a82a012ae6e61e7fab7
|
data/README.md
CHANGED
@@ -26,7 +26,7 @@ class Person < ActiveRecord::Base
|
|
26
26
|
end
|
27
27
|
```
|
28
28
|
|
29
|
-
Boom
|
29
|
+
**Boom!** Now you can `fetch` a person by their id, like below. When the person gets updated or touched, it will flush the cache, and the person will be reloaded on the next `fetch`.
|
30
30
|
|
31
31
|
```ruby
|
32
32
|
person = Person.fetch id # caches the person
|
@@ -46,7 +46,7 @@ class Person < ActiveRecord::Base
|
|
46
46
|
end
|
47
47
|
```
|
48
48
|
|
49
|
-
|
49
|
+
**Mathematical!** `cache_index` adds these index combinations to the list of cacheable things, so we can fetch single records with `fetch_by`, like this:
|
50
50
|
|
51
51
|
```ruby
|
52
52
|
person = Person.fetch_by name: 'Scott' # caches an awesome dude
|
@@ -59,10 +59,10 @@ person.update_attributes height: 71 # he shrunk? oh well, cache fl
|
|
59
59
|
person = Person.fetch_by weight: 175, height: 71 # fetched and cached with new height
|
60
60
|
```
|
61
61
|
|
62
|
-
Like noise in your life? Try `fetch_by!` (hard to say: "fetch-by-
|
62
|
+
Like noise in your life? Try `fetch_by!` (hard to say: "fetch-by-bang!").
|
63
63
|
|
64
64
|
```ruby
|
65
|
-
person = Person.fetch_by! name: 'Mork' # => ActiveRecord::RecordNotFound
|
65
|
+
person = Person.fetch_by! name: 'Mork' # => raises ActiveRecord::RecordNotFound
|
66
66
|
```
|
67
67
|
|
68
68
|
While `fetch_by` just pulls back just one record, you can fetch a collection with `fetch_where`:
|
@@ -130,7 +130,7 @@ dog = person.fetch_dog # finds and caches Fido with his new name
|
|
130
130
|
dog.fetch_person # gets the cached owner
|
131
131
|
```
|
132
132
|
|
133
|
-
For a slight optimization, specify a `cache_index` on the foreign key of the association, like in the `Kitten` example above. Memcacheable will then do a `fetch_by` or `fetch_where` as appropriate. The cost
|
133
|
+
For a slight optimization, specify a `cache_index` on the foreign key of the association, like in the `Kitten` example above. Memcacheable will then do a `fetch_by` or `fetch_where` as appropriate. **The cost:** two copies in the cache. **The gain:** when the parent changes but the children don't, the children can be _reloaded from the cache._ Like this:
|
134
134
|
|
135
135
|
```ruby
|
136
136
|
person.fetch_kittens # caches the kittens both by criteria and as an association
|
data/lib/memcacheable/fetcher.rb
CHANGED
data/lib/memcacheable/version.rb
CHANGED