kaminari-cache 0.1.3 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/kaminari-cache.gemspec +2 -2
- data/lib/kaminari-cache.rb +47 -23
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 40a6c8743a9b33e40dabbca3cfb4e6c9b68122d3
|
|
4
|
+
data.tar.gz: 0e066aca66deda9ba7110f936781dee0e410ad5f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 99c31e7aa6e5859939826fb112c71d5f5097f58b48966f5ffe3515c2b1af8d8474da690bbf36d8b992eb2897d4711acb8675808fb7982daedeb555cbda291efc
|
|
7
|
+
data.tar.gz: ffc6ab33fea68aaf79d5441e824f7082efac2360b9f1ce00466b3d1c4ae65491fca3db82eba84966a13a4925b4d9544ff80d1883f78304ab8277812bbdeca9cc
|
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.1.
|
|
1
|
+
0.1.4
|
data/kaminari-cache.gemspec
CHANGED
|
@@ -5,11 +5,11 @@
|
|
|
5
5
|
|
|
6
6
|
Gem::Specification.new do |s|
|
|
7
7
|
s.name = "kaminari-cache"
|
|
8
|
-
s.version = "0.1.
|
|
8
|
+
s.version = "0.1.4"
|
|
9
9
|
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
|
11
11
|
s.authors = ["Jim"]
|
|
12
|
-
s.date = "2013-11-
|
|
12
|
+
s.date = "2013-11-10"
|
|
13
13
|
s.description = "Kaminari Cache is a simple caching layer and sweeper for Kaminari pagination"
|
|
14
14
|
s.email = "powerjim@gmail.com"
|
|
15
15
|
s.extra_rdoc_files = [
|
data/lib/kaminari-cache.rb
CHANGED
|
@@ -37,9 +37,12 @@ module KaminariCache
|
|
|
37
37
|
:page => 1,
|
|
38
38
|
:per => Kaminari.config.max_per_page || Kaminari.config.default_per_page
|
|
39
39
|
)
|
|
40
|
-
|
|
40
|
+
key = cache_key(options)
|
|
41
|
+
entries = Rails.cache.fetch(key) do
|
|
42
|
+
Rails.logger.info "Cache miss: #{key.to_s}"
|
|
41
43
|
scope = self.page(options[:page]).per(options[:per])
|
|
42
|
-
scope = apply_sort(scope, options[:order])
|
|
44
|
+
scope = apply_sort(scope, options[:order]) if options[:order]
|
|
45
|
+
scope = apply_locale(scope, options[:locale]) if options[:locale]
|
|
43
46
|
Kaminari::PaginatableArray.new(scope.to_a,
|
|
44
47
|
:limit => scope.limit_value,
|
|
45
48
|
:offset => scope.offset_value,
|
|
@@ -48,32 +51,53 @@ module KaminariCache
|
|
|
48
51
|
end
|
|
49
52
|
end
|
|
50
53
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
54
|
+
private
|
|
55
|
+
def cache_key(options)
|
|
56
|
+
key = [:kaminari, self.name.pluralize.downcase]
|
|
57
|
+
key << options[:page]
|
|
58
|
+
key << options[:per]
|
|
59
|
+
key << [:locale, options[:locale]] if options[:locale]
|
|
60
|
+
key << [:order, options[:order]] if options[:order]
|
|
61
|
+
expanded_key(key)
|
|
62
|
+
end
|
|
58
63
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
when Hash
|
|
66
|
-
order.each do |k, v|
|
|
67
|
-
if v.empty?
|
|
68
|
-
scope.order! k
|
|
64
|
+
def expanded_key(key)
|
|
65
|
+
return key.cache_key.to_s if key.respond_to?(:cache_key)
|
|
66
|
+
case key
|
|
67
|
+
when Array
|
|
68
|
+
if key.size > 1
|
|
69
|
+
key = key.collect{|element| expanded_key(element)}
|
|
69
70
|
else
|
|
70
|
-
|
|
71
|
+
key = key.first
|
|
71
72
|
end
|
|
72
|
-
|
|
73
|
+
when Hash
|
|
74
|
+
key = key.sort_by { |k,_| k.to_s }.collect{|k,v| "#{k}=#{v}"}
|
|
75
|
+
end
|
|
76
|
+
key.to_param
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def apply_sort(scope, order)
|
|
80
|
+
case order
|
|
81
|
+
when Symbol
|
|
82
|
+
scope.order! order
|
|
83
|
+
when String
|
|
84
|
+
scope.order! order
|
|
85
|
+
when Hash
|
|
86
|
+
order.each do |k, v|
|
|
87
|
+
if v.empty?
|
|
88
|
+
scope.order! k
|
|
89
|
+
else
|
|
90
|
+
scope.order! "#{k.to_s} #{v.to_s}"
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
scope
|
|
95
|
+
end
|
|
96
|
+
def apply_locale(scope, locale)
|
|
97
|
+
scope = scope.with_translations(locale) if scope.respond_to? :with_translations
|
|
98
|
+
scope
|
|
73
99
|
end
|
|
74
|
-
scope
|
|
75
100
|
end
|
|
76
|
-
end
|
|
77
101
|
end
|
|
78
102
|
|
|
79
103
|
ActiveRecord::Base.send(:include, KaminariCache)
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: kaminari-cache
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.4
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Jim
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2013-11-
|
|
11
|
+
date: 2013-11-10 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: kaminari-cache
|