cachecataz 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +2 -0
- data/README.rdoc +15 -2
- data/VERSION +1 -1
- metadata +3 -3
data/Gemfile.lock
CHANGED
data/README.rdoc
CHANGED
@@ -60,7 +60,7 @@ For the example above the namespace key would be "name:#{element.user_id}", whic
|
|
60
60
|
|
61
61
|
Basic premise: An Element belongs_to a User and a Widget belongs_to a User as well. The "something" partial displays data primarily related to
|
62
62
|
the Element but also displays data from the related Widget. I want to have a sweeper that observes changes in the Widget model and expires the
|
63
|
-
namespace for the Element. (can be kinda confusing, but makes sense in the context of a cache that is model dependent.
|
63
|
+
namespace for the Element. (can be kinda confusing, but makes sense in the context of a cache that is model dependent.)
|
64
64
|
|
65
65
|
Generate a cache key:
|
66
66
|
# ** Model **
|
@@ -76,11 +76,24 @@ Generate a cache key:
|
|
76
76
|
<% end %>
|
77
77
|
|
78
78
|
# ** Observer **
|
79
|
-
class WidgetObserver < ActiveRecord::Observer
|
79
|
+
class WidgetObserver < ActiveRecord::Observer
|
80
80
|
after_update(widget)
|
81
81
|
Element.expire_namespace(:user, widget.attributes) # can also just pass {:user_id => widget.user_id} as the scope_hash, scope requires :user_id
|
82
82
|
end
|
83
83
|
end
|
84
|
+
|
85
|
+
# ** Another Observer ** Why expire_fragment is available? not important
|
86
|
+
class ElementObserver < CacheSweepingObserver
|
87
|
+
after_update(element)
|
88
|
+
expire_fragment(element.cache_key(:user, :id)) # Will only expire a single key "0:user:1/12" if user_id == 1 and id == 12
|
89
|
+
end
|
90
|
+
|
91
|
+
after_create(element)
|
92
|
+
element.expire_namespace(:user) # will expire the entire namespace for cache_scope :user for user 1 if user_id ==1
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
# by default the scope_hash on any expire_namespace call for an instance is self.attributes
|
84
97
|
|
85
98
|
== TODO
|
86
99
|
post more info on how to use cachecataz with a cache that is not Rails.cache (it's very simple), but wanted to get the basics released
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.2
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cachecataz
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 31
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 2
|
10
|
+
version: 0.1.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Brandon Dewitt
|