kasket 0.7.5 → 0.7.6
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +132 -6
- data/lib/kasket.rb +1 -2
- data/lib/kasket/configuration_mixin.rb +4 -5
- data/test/transaction_test.rb +1 -1
- metadata +2 -4
- data/LICENSE +0 -20
data/README.rdoc
CHANGED
@@ -1,17 +1,143 @@
|
|
1
|
-
=
|
1
|
+
= Kasket
|
2
|
+
=== Puts a cap on your queries
|
3
|
+
A caching layer for ActiveRecord
|
2
4
|
|
3
|
-
|
5
|
+
Developed and used on http://zendesk.com.
|
6
|
+
|
7
|
+
== Sponsored by Zendesk - Enlightened Customer Support
|
8
|
+
|
9
|
+
== Description
|
10
|
+
|
11
|
+
Kasket is a safe way to cache your database queries in memcached.
|
12
|
+
Designed to be as small and simple as possible, and to get out of the way when it is not safe to cache.
|
13
|
+
|
14
|
+
You can configure exactly what models to cache and what type of queries to cache.
|
15
|
+
|
16
|
+
=== Features
|
17
|
+
|
18
|
+
* Declarative configuration
|
19
|
+
* Collection caching as well as caching of single instances
|
20
|
+
* Automatic cache expiry on database migration
|
21
|
+
* Automatic cache expiry in Kasket udates
|
22
|
+
* Very small code base
|
23
|
+
|
24
|
+
== Setting up Kasket
|
25
|
+
|
26
|
+
Kasket is set up by simply calling Kasket.setup in an initializer script.
|
27
|
+
This will include the required modules into the ActiveRecord
|
28
|
+
|
29
|
+
=== Options
|
30
|
+
|
31
|
+
By default, Kasket will cache instance collection with a maximum length of 100.
|
32
|
+
You can everride this by passing the :max_collection_size option to the Kasket.setup call:
|
33
|
+
|
34
|
+
Kasket.setup(:max_collection_size => 50)
|
35
|
+
|
36
|
+
== Configuring caching of your models
|
37
|
+
|
38
|
+
You can configure Kasket for any ActiveRecord model, and subclasses will automatically inherit the caching
|
39
|
+
configuration.
|
40
|
+
|
41
|
+
If you have an Account model, you can can do the simplest caching configuration like:
|
42
|
+
|
43
|
+
Account.has_kasket
|
44
|
+
|
45
|
+
This will add a caching index on the id attribute of the Account model,
|
46
|
+
and will make sure that all your calls like Account.find(1) and Account.find_by_id(1) will be cached.
|
47
|
+
All other calls ( say Account.find_by_subdomain('zendesk') ) are untouched.
|
48
|
+
|
49
|
+
If you wanted to configure a caching index on the subdomain attribute of the Account model, you would simply write
|
50
|
+
|
51
|
+
Account.has_kasket_on :subdomain
|
52
|
+
|
53
|
+
This would add caching to calls like:
|
54
|
+
* Account.find_by_subdomain('zendesk')
|
55
|
+
* Account.find_all_by_subdomain('zendesk')
|
56
|
+
|
57
|
+
and all other ways of expressing lookups on subdomain.
|
58
|
+
|
59
|
+
== Cache expiry
|
60
|
+
|
61
|
+
The goal of Kasket is to be as safe as possible to use, so the cache is expired in a number of situations
|
62
|
+
* When you save a model instance
|
63
|
+
* When your database schema changes
|
64
|
+
* When you install a new version of Kasket
|
65
|
+
* When you ask it to
|
66
|
+
|
67
|
+
=== Cahce expiry on instance save
|
68
|
+
|
69
|
+
When you save a model instance, Kasket will calculate the cache entries to expire.
|
70
|
+
|
71
|
+
=== Cache expiry on database schema changes
|
72
|
+
|
73
|
+
All Kasket cache keys contain a hash of the column names of the table associated with the model.
|
74
|
+
If you somehow change your table schema, all cache entries for that table will automatically expire
|
75
|
+
|
76
|
+
=== Cache expiry on Kasket upgrades
|
77
|
+
|
78
|
+
All Kasket cache keys contain the Kasket version number, so upgrading Kasket will expire all Kasket cache entries.
|
79
|
+
|
80
|
+
=== Manually expiring caches
|
81
|
+
|
82
|
+
If you have model methods that update the database behind the back of ActiveRecord, you need to mark these methods
|
83
|
+
as beeing dirty.
|
84
|
+
|
85
|
+
Account.kasket_dirty_methods :update_last_action
|
86
|
+
|
87
|
+
This will make sure the clear the cache entries for the current instance when you call update_last_action
|
88
|
+
|
89
|
+
== How does this work?
|
90
|
+
|
91
|
+
== Known issues
|
92
|
+
|
93
|
+
We have only used and tested Kasket on MySql.
|
94
|
+
|
95
|
+
Let us know if you find any.
|
96
|
+
|
97
|
+
== Requirements
|
98
|
+
|
99
|
+
* ActiveRecord 2.3.x
|
100
|
+
|
101
|
+
== Isn't this what Cache Money does?
|
102
|
+
|
103
|
+
Absolutely, but cache money does so much more.
|
104
|
+
|
105
|
+
* Cache Money has way more features than what we need
|
106
|
+
* The Cache Money code is overly complex
|
107
|
+
* Cache Monet seems abandoned
|
4
108
|
|
5
109
|
== Note on Patches/Pull Requests
|
6
110
|
|
7
111
|
* Fork the project.
|
8
112
|
* Make your feature addition or bug fix.
|
9
|
-
* Add tests for it. This is important so I don't break it in a
|
10
|
-
future version unintentionally.
|
113
|
+
* Add tests for it. This is important so I don't break it in a future version unintentionally.
|
11
114
|
* Commit, do not mess with rakefile, version, or history.
|
12
115
|
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
13
116
|
* Send me a pull request. Bonus points for topic branches.
|
14
117
|
|
15
|
-
==
|
118
|
+
== LICENSE:
|
119
|
+
|
120
|
+
(The MIT License)
|
121
|
+
|
122
|
+
Copyright (c) 2010 Zendesk
|
123
|
+
|
124
|
+
Permission is hereby granted, free of charge, to any person
|
125
|
+
obtaining a copy of this software and associated documentation
|
126
|
+
files (the "Software"), to deal in the Software without
|
127
|
+
restriction, including without limitation the rights to use,
|
128
|
+
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
129
|
+
copies of the Software, and to permit persons to whom the
|
130
|
+
Software is furnished to do so, subject to the following
|
131
|
+
conditions:
|
132
|
+
|
133
|
+
The above copyright notice and this permission notice shall be
|
134
|
+
included in all copies or substantial portions of the Software.
|
16
135
|
|
17
|
-
|
136
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
137
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
138
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
139
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
140
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
141
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
142
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
143
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
data/lib/kasket.rb
CHANGED
@@ -7,7 +7,6 @@ require 'kasket/active_record_patches'
|
|
7
7
|
module Kasket
|
8
8
|
autoload :ConfigurationMixin, 'kasket/configuration_mixin'
|
9
9
|
autoload :ReloadAssociationMixin, 'kasket/reload_association_mixin'
|
10
|
-
autoload :RackMiddleware, 'kasket/rack_middleware'
|
11
10
|
autoload :Query, 'kasket/query'
|
12
11
|
|
13
12
|
CONFIGURATION = {:max_collection_size => 100}
|
@@ -15,7 +14,7 @@ module Kasket
|
|
15
14
|
class Version
|
16
15
|
MAJOR = 0
|
17
16
|
MINOR = 7
|
18
|
-
PATCH =
|
17
|
+
PATCH = 6
|
19
18
|
STRING = "#{MAJOR}.#{MINOR}.#{PATCH}"
|
20
19
|
end
|
21
20
|
|
@@ -9,15 +9,15 @@ module Kasket
|
|
9
9
|
module ConfigurationMixin
|
10
10
|
|
11
11
|
def without_kasket(&block)
|
12
|
-
old_value =
|
13
|
-
|
12
|
+
old_value = Thread.current['kasket_disabled'] || false
|
13
|
+
Thread.current['kasket_disabled'] = true
|
14
14
|
yield
|
15
15
|
ensure
|
16
|
-
|
16
|
+
Thread.current['kasket_disabled'] = old_value
|
17
17
|
end
|
18
18
|
|
19
19
|
def use_kasket?
|
20
|
-
|
20
|
+
!Thread.current['kasket_disabled']
|
21
21
|
end
|
22
22
|
|
23
23
|
def kasket_parser
|
@@ -69,7 +69,6 @@ module Kasket
|
|
69
69
|
end
|
70
70
|
|
71
71
|
def has_kasket_on(*args)
|
72
|
-
@use_kasket = true
|
73
72
|
attributes = args.sort! { |x, y| x.to_s <=> y.to_s }
|
74
73
|
if attributes != [:id] && !kasket_indices.include?([:id])
|
75
74
|
has_kasket_on(:id)
|
data/test/transaction_test.rb
CHANGED
@@ -15,7 +15,7 @@ class TransactionTest < ActiveSupport::TestCase
|
|
15
15
|
setup { Comment.has_kasket }
|
16
16
|
should "disable kasket" do
|
17
17
|
Post.transaction do
|
18
|
-
assert_equal
|
18
|
+
assert_equal false, Comment.use_kasket?
|
19
19
|
assert_equal false, Post.use_kasket?
|
20
20
|
Comment.transaction do
|
21
21
|
assert_equal false, Post.use_kasket?
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kasket
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mick Staugaard
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2010-02-
|
13
|
+
date: 2010-02-08 00:00:00 +01:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -70,12 +70,10 @@ executables: []
|
|
70
70
|
extensions: []
|
71
71
|
|
72
72
|
extra_rdoc_files:
|
73
|
-
- LICENSE
|
74
73
|
- README.rdoc
|
75
74
|
files:
|
76
75
|
- .document
|
77
76
|
- .gitignore
|
78
|
-
- LICENSE
|
79
77
|
- README.rdoc
|
80
78
|
- Rakefile
|
81
79
|
- lib/kasket.rb
|
data/LICENSE
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
Copyright (c) 2009 Mick Staugaard
|
2
|
-
|
3
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
-
a copy of this software and associated documentation files (the
|
5
|
-
"Software"), to deal in the Software without restriction, including
|
6
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
-
permit persons to whom the Software is furnished to do so, subject to
|
9
|
-
the following conditions:
|
10
|
-
|
11
|
-
The above copyright notice and this permission notice shall be
|
12
|
-
included in all copies or substantial portions of the Software.
|
13
|
-
|
14
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|