cache_key_monster 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +42 -6
- data/cache_key_monster.gemspec +1 -1
- data/lib/cache_key_monster/version.rb +1 -1
- metadata +2 -2
data/README.md
CHANGED
@@ -1,7 +1,47 @@
|
|
1
|
-
#
|
1
|
+
# OM! NOM! NOM!
|
2
|
+
|
3
|
+
ME CACHE KEY MONSTER. ME LOVE TO MAKE CACHE KEYS EASY!
|
4
|
+
|
5
|
+
![The loveable, furry, non-infringing cache key monster](https://github.com/dougrohde/cache_key_monster/raw/master/cache_key_monster.jpg "The loveable, furry, non-infringing cache key monster")
|
6
|
+
|
7
|
+
## CacheKeyMonster
|
2
8
|
|
3
9
|
CacheKeyMonster provides a lightweight, declarative-style syntax for adding the cache_key method which is used by Rails' "cache" method. It allows you to cache Plain Old Ruby objects based on their constituent data. This is useful for objects that are transient by their very nature.
|
4
10
|
|
11
|
+
|
12
|
+
## Usage
|
13
|
+
|
14
|
+
CacheKeyMonster is designed for caching things that are transient by their nature. In the case where HTML fragment
|
15
|
+
caching might not be a reasonable option, this provides an alternative.
|
16
|
+
|
17
|
+
For example, say you have a resource that displays an up-to-date, ordered list of baseball statistics. In this case, the resource isn't a represented by a single object. Instead,
|
18
|
+
it's the individual player statistics that make up the resource.
|
19
|
+
|
20
|
+
In the example below, BattingLeaders accepts an array of player statistics.
|
21
|
+
|
22
|
+
The cache_key declaration accepts a lambda for its key option. Here, when cache_key gets called on an instance of BattingLeaders,
|
23
|
+
it will resolve to a concatenated string composed of each individual stat record's id and avg fields, in order. If any
|
24
|
+
of the players' averages changes, or the order changes, the resource will generate a new cache key.
|
25
|
+
Of course this does require a request to the database each time, but generally this is cheaper than rendering.
|
26
|
+
|
27
|
+
```
|
28
|
+
class BattingLeaders
|
29
|
+
|
30
|
+
include CacheKeyMonster::CacheKey
|
31
|
+
|
32
|
+
cache_key key: ->(obj){obj.leaders.map(&:id).join + obj.leaders.map(&:avg).join}
|
33
|
+
|
34
|
+
attr_accessor :leaders
|
35
|
+
|
36
|
+
def initialize(leaders)
|
37
|
+
@leaders = leaders
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
end
|
42
|
+
```
|
43
|
+
|
44
|
+
|
5
45
|
## Installation
|
6
46
|
|
7
47
|
Add this line to your application's Gemfile:
|
@@ -15,11 +55,7 @@ And then execute:
|
|
15
55
|
Or install it yourself as:
|
16
56
|
|
17
57
|
$ gem install cache_key_monster
|
18
|
-
|
19
|
-
## Usage
|
20
|
-
|
21
|
-
TODO: Write usage instructions here
|
22
|
-
|
58
|
+
|
23
59
|
## Contributing
|
24
60
|
|
25
61
|
1. Fork it
|
data/cache_key_monster.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |gem|
|
|
10
10
|
gem.email = ["doug.rohde@tstmedia.com"]
|
11
11
|
gem.description = %q{A simple way to provide cache_key method to Plain Old Ruby objects}
|
12
12
|
gem.summary = %q{A simple way to provide cache_key method to Plain Old Ruby objects}
|
13
|
-
gem.homepage = ""
|
13
|
+
gem.homepage = "https://github.com/dougrohde/cache_key_monster"
|
14
14
|
|
15
15
|
gem.files = `git ls-files`.split($/)
|
16
16
|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: cache_key_monster
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.2
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Doug Rohde
|
@@ -54,7 +54,7 @@ files:
|
|
54
54
|
- spec/support/no_key_provided.rb
|
55
55
|
- spec/support/player.rb
|
56
56
|
has_rdoc: true
|
57
|
-
homepage:
|
57
|
+
homepage: https://github.com/dougrohde/cache_key_monster
|
58
58
|
licenses: []
|
59
59
|
|
60
60
|
post_install_message:
|