arid_cache 0.2.5 → 0.2.6
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +2 -1
- data/VERSION +1 -1
- data/arid_cache.gemspec +2 -2
- data/lib/arid_cache/cache_proxy.rb +1 -1
- data/test/arid_cache_test.rb +15 -4
- metadata +2 -2
data/README.rdoc
CHANGED
@@ -281,7 +281,8 @@ The version of Rails shouldn't matter much, but it's working on 2.3.4.
|
|
281
281
|
|
282
282
|
== Known Issues
|
283
283
|
|
284
|
-
1. Caches that contains duplicate records
|
284
|
+
1. <b>Caches that contains duplicate records will only return unique records on subsequent calls</b>. 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_all_by_id([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.
|
285
|
+
2. <b>You can't cache polymorphic arrays</b> e.g. [#<User id: 1>, #<Pet id: 5>] because it expects all ActiveRecords to be of the same class. We could accept a <tt>:polymorphic => true</tt> option but I don't think this is a great idea because instantiating all the records would result in a lot of queries to the individual tables.
|
285
286
|
|
286
287
|
== Wish List / Coming Soon
|
287
288
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.6
|
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.6"
|
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-21}
|
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
|
}
|
@@ -113,7 +113,7 @@ module AridCache
|
|
113
113
|
|
114
114
|
def fetch_and_paginate
|
115
115
|
if combined_options.include?(:order) # order and paginate in the database
|
116
|
-
klass.paginate(cached.ids, opts_for_find.merge(opts_for_paginate))
|
116
|
+
klass.paginate(cached.ids, { :total_entries => cached.ids.size }.merge(opts_for_find.merge(opts_for_paginate)))
|
117
117
|
else # paginate in memory
|
118
118
|
paged_ids = cached.ids.paginate(opts_for_paginate)
|
119
119
|
paged_ids.replace(klass.find_all_by_id(paged_ids, opts_for_find(paged_ids)))
|
data/test/arid_cache_test.rb
CHANGED
@@ -291,7 +291,7 @@ class AridCacheTest < ActiveSupport::TestCase
|
|
291
291
|
assert_equal User.successful.find(:all, :order => 'name DESC'), User.cached_most_successful
|
292
292
|
assert_equal User.successful.find(:all, :order => 'name DESC'), User.cached_most_successful
|
293
293
|
end
|
294
|
-
|
294
|
+
|
295
295
|
test "should not raise an error if all cached ids cannot be found" do
|
296
296
|
@user.cached_companies
|
297
297
|
key = @user.arid_cache_key('companies')
|
@@ -301,7 +301,7 @@ class AridCacheTest < ActiveSupport::TestCase
|
|
301
301
|
assert_nothing_raised { @user.cached_companies }
|
302
302
|
assert_equal @user.cached_companies, @user.companies
|
303
303
|
end
|
304
|
-
|
304
|
+
|
305
305
|
test "should not raise an error if all cached ids cannot be found while paginating" do
|
306
306
|
@user.cached_companies
|
307
307
|
key = @user.arid_cache_key('companies')
|
@@ -311,13 +311,24 @@ class AridCacheTest < ActiveSupport::TestCase
|
|
311
311
|
assert_nothing_raised { @user.cached_companies(:page => 1, :order => 'name DESC') }
|
312
312
|
assert_equal @user.cached_companies(:page => 1, :order => 'name DESC'), @user.companies.paginate(:page => 1, :order => 'name DESC')
|
313
313
|
end
|
314
|
-
|
314
|
+
|
315
315
|
test "should handle empty collections" do
|
316
316
|
@user.cached_empty_collection { [] }
|
317
317
|
assert_nothing_raised { @user.cached_empty_collection }
|
318
318
|
assert_nothing_raised { @user.cached_empty_collection }
|
319
319
|
end
|
320
|
-
|
320
|
+
|
321
|
+
test "should return proper paginate results when we include order" do
|
322
|
+
total = @user.companies.count
|
323
|
+
assert_queries(2) do
|
324
|
+
@user.cached_companies
|
325
|
+
page = @user.cached_companies(:page => 2, :per_page => 3, :order => 'name desc') # call again to get cached results
|
326
|
+
assert_equal total, page.total_entries
|
327
|
+
assert_equal 2, page.current_page
|
328
|
+
assert_equal (total/3.0).ceil, page.total_pages
|
329
|
+
end
|
330
|
+
end
|
331
|
+
|
321
332
|
#
|
322
333
|
# Tests requiring manual verification by looking at the SQL logs.
|
323
334
|
# TODO move these to a separate class.
|
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.6
|
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-21 00:00:00 +08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|