arid_cache 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +31 -3
- data/VERSION +1 -1
- data/arid_cache.gemspec +2 -2
- data/lib/arid_cache/helpers.rb +9 -15
- data/test/test_helper.rb +1 -1
- metadata +2 -2
data/README.rdoc
CHANGED
@@ -105,7 +105,7 @@ You can pass a hash of options to <tt>instance_caches</tt> and <tt>class_caches<
|
|
105
105
|
highlight_tracks(:include => [:album, :artist]) do
|
106
106
|
cached_tracks(:limit => 10, :include => [:album, :artist])
|
107
107
|
end
|
108
|
-
highlight_artists do
|
108
|
+
highlight_artists(:order => nil) do # override the global :order option
|
109
109
|
cached_artists(:limit => 10)
|
110
110
|
end
|
111
111
|
highlight_albums(:include => :artist) do
|
@@ -259,11 +259,34 @@ For example, assume we have a <tt>named_scope :active</tt> on <tt>User</tt> whic
|
|
259
259
|
* If you only request a count AridCache will only select the count. See <i>Cached Counts</i>.
|
260
260
|
* If a collection has already been loaded, you get the count for free. See <i>Cached Counts</i>.
|
261
261
|
|
262
|
+
== Compatibility
|
263
|
+
|
264
|
+
Tested on Ruby 1.8.6 and 1.8.7. Should be compatible with 1.9.
|
265
|
+
|
266
|
+
For Ruby < 1.8.7 you probably want to include the following to extend the Array class with a <tt>count</tt> method. Otherwise your <tt>cached_<key>_count</tt> calls probably won't work:
|
267
|
+
|
268
|
+
Array.class_eval { alias count size }
|
269
|
+
|
270
|
+
The version of Rails shouldn't matter much, but it's working on 2.3.4.
|
271
|
+
|
272
|
+
== Resources & Metrics
|
273
|
+
|
274
|
+
|
275
|
+
* {RDoc}[http://rdoc.info/projects/kjvarga/arid_cache]
|
276
|
+
* {GetCaliper Metrics}[http://getcaliper.com/caliper/project?repo=git%3A%2F%2Fgithub.com%2Fkjvarga%2Farid_cache.git]
|
277
|
+
|
262
278
|
== Known Issues
|
263
279
|
|
264
|
-
1. Caches that contains duplicate records (for example from the result of a join), will only return unique records on subsequent calls. This is because of the way <tt>find</tt> works when selecting multiple ids. For example, if your query returns <tt>[#<User id: 1>, #<User id: 1>, #<User id: 1>]</tt>, the IDs are cached as <tt>[1,1,1]</tt>. On the next call to the cache we load the IDs using <tt>
|
280
|
+
1. Caches that contains duplicate records (for example from the result of a join), will only return unique records on subsequent calls. This is because of the way <tt>find</tt> works when selecting multiple ids. For example, if your query returns <tt>[#<User id: 1>, #<User id: 1>, #<User id: 1>]</tt>, the IDs are cached as <tt>[1,1,1]</tt>. On the next call to the cache we load the IDs using <tt>User.find([1,1,1])</tt> which returns <tt>[#<User id: 1>]</tt>, not <tt>[#<User id: 1>, #<User id: 1>, #<User id: 1>]</tt> as you might have expected.
|
281
|
+
|
282
|
+
== Wish List / Coming Soon
|
283
|
+
|
284
|
+
* Some kind of memoize option.
|
285
|
+
* Priming caches. Warm up the cache for all models based on the information in the instance and class cache configurations. Would need to know when you want to prime counts as well.
|
286
|
+
* The ability to <tt>include AridCache</tt> on any class or module.
|
287
|
+
* An option to bypass ID caching when you want to store records in the cache.
|
265
288
|
|
266
|
-
==
|
289
|
+
== Contributors
|
267
290
|
|
268
291
|
Contributions are welcome! Please,
|
269
292
|
|
@@ -273,6 +296,11 @@ Contributions are welcome! Please,
|
|
273
296
|
* Commit (don't mess with the Rakefile, version, or history).
|
274
297
|
* Send me a pull request.
|
275
298
|
|
299
|
+
|
300
|
+
==== Thank-you to these contributors to AridCache:
|
301
|
+
|
302
|
+
* {Sutto}[http://github.com/Sutto]
|
303
|
+
|
276
304
|
== Copyright
|
277
305
|
|
278
306
|
Copyright (c) 2009 Karl Varga. See LICENSE for details.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.3
|
data/arid_cache.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{arid_cache}
|
8
|
-
s.version = "0.2.
|
8
|
+
s.version = "0.2.3"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Karl Varga"]
|
12
|
-
s.date = %q{2010-01-
|
12
|
+
s.date = %q{2010-01-19}
|
13
13
|
s.description = %q{AridCache makes caching easy and effective. AridCache supports caching on all your model named scopes, class methods and instance methods right out of the box. AridCache prevents caching logic from cluttering your models and clarifies your logic by making explicit calls to cached result sets.
|
14
14
|
AridCache is designed for handling large, expensive ActiveRecord collections but is equally useful for caching anything else as well.
|
15
15
|
}
|
data/lib/arid_cache/helpers.rb
CHANGED
@@ -64,22 +64,16 @@ module AridCache
|
|
64
64
|
private
|
65
65
|
|
66
66
|
def method_for_cached(object, key, fetch_method=:fetch, method_name=nil)
|
67
|
-
method_name = "cached_" + (method_name || key)
|
68
|
-
|
69
|
-
(
|
70
|
-
|
71
|
-
|
72
|
-
AridCache.cache.send(fetch_method, self, key, opts, &block)
|
73
|
-
end
|
67
|
+
method_name = ("cached_" + (method_name || key)).gsub(/[^\w\!\?]/, '_')
|
68
|
+
method_body = <<-END
|
69
|
+
def #{method_name}(*args, &block)
|
70
|
+
opts = args.empty? ? {} : args.first
|
71
|
+
AridCache.cache.send(#{fetch_method.inspect}, self, #{key.inspect}, opts, &block)
|
74
72
|
end
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
AridCache.cache.send(fetch_method, self, key, opts, &block)
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
73
|
+
END
|
74
|
+
# Get the correct object
|
75
|
+
object = (class << object; self; end) if object.is_a?(Class)
|
76
|
+
object.class_eval(method_body, __FILE__, __LINE__)
|
83
77
|
end
|
84
78
|
end
|
85
79
|
end
|
data/test/test_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: arid_cache
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Karl Varga
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-01-
|
12
|
+
date: 2010-01-19 00:00:00 +08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|