cache_key_for 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.rspec +1 -0
- data/Gemfile.lock +43 -1
- data/README.md +11 -9
- data/Rakefile +2 -2
- data/cache_key_for.gemspec +6 -0
- data/lib/cache_key_for/cache_key_for_helper.rb +26 -8
- data/lib/cache_key_for/cache_key_for_view_helper.rb +2 -2
- data/lib/cache_key_for/railtie.rb +3 -2
- data/lib/cache_key_for/version.rb +1 -1
- data/lib/cache_key_for.rb +1 -1
- metadata +86 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8c625fdf466a0e82fa1c2bb3df30ffecf5044332
|
4
|
+
data.tar.gz: e3d7c1ccf821298f34890920e4e31d4b8b1115bf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 37ad16b96072909e6d821841fae60050f7cf26b510857563b0671e50c0882aefb98b2eb39f26c975a42753b12da4c88a2fb521037e8a9acc92d5b886a9a3d017
|
7
|
+
data.tar.gz: 5c991a6bfedacafc4f30526f37d6f0b4a7af555afba85a08e4850619cf104d1f24bcbec7e26ab16c6b770d9d5b74ea16ff8a8dc0c92787826d6cfdeb76784930
|
data/.gitignore
CHANGED
data/.rspec
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
cache_key_for (0.1.
|
4
|
+
cache_key_for (0.1.2)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
@@ -30,16 +30,38 @@ GEM
|
|
30
30
|
rake
|
31
31
|
thor (>= 0.14.0)
|
32
32
|
builder (3.2.2)
|
33
|
+
byebug (8.2.2)
|
34
|
+
codeclimate-test-reporter (0.5.0)
|
35
|
+
simplecov (>= 0.7.1, < 1.0.0)
|
36
|
+
coderay (1.1.1)
|
37
|
+
coveralls (0.8.13)
|
38
|
+
json (~> 1.8)
|
39
|
+
simplecov (~> 0.11.0)
|
40
|
+
term-ansicolor (~> 1.3)
|
41
|
+
thor (~> 0.19.1)
|
42
|
+
tins (~> 1.6.0)
|
33
43
|
diff-lcs (1.2.5)
|
44
|
+
docile (1.1.5)
|
34
45
|
erubis (2.7.0)
|
46
|
+
fuubar (2.0.0)
|
47
|
+
rspec (~> 3.0)
|
48
|
+
ruby-progressbar (~> 1.4)
|
35
49
|
i18n (0.7.0)
|
36
50
|
json (1.8.2)
|
37
51
|
loofah (2.0.1)
|
38
52
|
nokogiri (>= 1.5.9)
|
53
|
+
method_source (0.8.2)
|
39
54
|
mini_portile (0.6.2)
|
40
55
|
minitest (5.5.1)
|
41
56
|
nokogiri (1.6.6.2)
|
42
57
|
mini_portile (~> 0.6.0)
|
58
|
+
pry (0.10.3)
|
59
|
+
coderay (~> 1.1.0)
|
60
|
+
method_source (~> 0.8.1)
|
61
|
+
slop (~> 3.4)
|
62
|
+
pry-byebug (3.3.0)
|
63
|
+
byebug (~> 8.0)
|
64
|
+
pry (~> 0.10)
|
43
65
|
rack (1.6.0)
|
44
66
|
rack-test (0.6.3)
|
45
67
|
rack (>= 1.0)
|
@@ -57,6 +79,10 @@ GEM
|
|
57
79
|
rake (>= 0.8.7)
|
58
80
|
thor (>= 0.18.1, < 2.0)
|
59
81
|
rake (10.4.2)
|
82
|
+
rspec (3.2.0)
|
83
|
+
rspec-core (~> 3.2.0)
|
84
|
+
rspec-expectations (~> 3.2.0)
|
85
|
+
rspec-mocks (~> 3.2.0)
|
60
86
|
rspec-core (3.2.1)
|
61
87
|
rspec-support (~> 3.2.0)
|
62
88
|
rspec-expectations (3.2.0)
|
@@ -74,9 +100,19 @@ GEM
|
|
74
100
|
rspec-mocks (~> 3.2.0)
|
75
101
|
rspec-support (~> 3.2.0)
|
76
102
|
rspec-support (3.2.2)
|
103
|
+
ruby-progressbar (1.7.5)
|
104
|
+
simplecov (0.11.2)
|
105
|
+
docile (~> 1.1.0)
|
106
|
+
json (~> 1.8)
|
107
|
+
simplecov-html (~> 0.10.0)
|
108
|
+
simplecov-html (0.10.0)
|
109
|
+
slop (3.6.0)
|
77
110
|
sqlite3 (1.3.10)
|
111
|
+
term-ansicolor (1.3.2)
|
112
|
+
tins (~> 1.0)
|
78
113
|
thor (0.19.1)
|
79
114
|
thread_safe (0.3.4)
|
115
|
+
tins (1.6.0)
|
80
116
|
tzinfo (1.2.2)
|
81
117
|
thread_safe (~> 0.1)
|
82
118
|
|
@@ -86,7 +122,13 @@ PLATFORMS
|
|
86
122
|
DEPENDENCIES
|
87
123
|
appraisal (~> 1.0)
|
88
124
|
cache_key_for!
|
125
|
+
codeclimate-test-reporter (~> 0.5.0)
|
126
|
+
coveralls (~> 0.8.13)
|
127
|
+
fuubar (~> 2.0.0)
|
128
|
+
pry (~> 0.10.3)
|
129
|
+
pry-byebug (~> 3.3.0)
|
89
130
|
rspec-rails (~> 3.1)
|
131
|
+
simplecov (~> 0.11.2)
|
90
132
|
sqlite3 (~> 1.3)
|
91
133
|
|
92
134
|
BUNDLED WITH
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# CacheKeyFor [![Build Status](https://travis-ci.org/efigence/cache_key_for.svg?branch=master)](https://travis-ci.org/efigence/cache_key_for)
|
1
|
+
# CacheKeyFor [![Build Status](https://travis-ci.org/efigence/cache_key_for.svg?branch=master)](https://travis-ci.org/efigence/cache_key_for) [![Coverage Status](https://coveralls.io/repos/github/efigence/cache_key_for/badge.svg?branch=master)](https://coveralls.io/github/efigence/cache_key_for?branch=master) [![Code Climate](https://codeclimate.com/github/efigence/cache_key_for/badges/gpa.svg)](https://codeclimate.com/github/efigence/cache_key_for)
|
2
2
|
Comprehensive cache key generator (complements Rails `cache` helper)
|
3
3
|
|
4
4
|
How to design a perfect cache key? This project's goal is to provide the bulletproof solution for most use cases.
|
@@ -14,12 +14,18 @@ It should be run as a gem and included in your `Gemfile`:
|
|
14
14
|
### \#cache_key_for
|
15
15
|
|
16
16
|
Features:
|
17
|
-
*
|
18
|
-
*
|
19
|
-
*
|
17
|
+
* ORM agnostic
|
18
|
+
* works with arrays and Plain Old Ruby Objects (POROs) (just provide: #id, #updated_at)
|
19
|
+
* supports locale
|
20
|
+
* recognizes subdomains
|
20
21
|
* deletion from and addition to collections sorted in ascending order (via embedded `count` in the key)
|
21
22
|
* accepts `cache_owner_cache_key` for personalized cache, eg. current_company.cache_key, current_user.cache_key etc.
|
22
|
-
*
|
23
|
+
* filters params with proper non-utf8 data handling for key generation
|
24
|
+
* recognizes pagination via params (performs well for less than 100 objects per page)
|
25
|
+
* includes all params, not only GET's `query` params, which enables submitting of complex forms via POST,
|
26
|
+
which - otherwise - would have query string longer than 2048 characters (Microsoft Internet Explorer)
|
27
|
+
* optional whitelist of first level parameters to prevent accidentally generating duplicated cache
|
28
|
+
* strips utm_* params
|
23
29
|
* optional suffix for:
|
24
30
|
* expiry tags (unlike :expires_in cache option, this offers full :file_store storage compatibility)
|
25
31
|
* any edge cases
|
@@ -79,7 +85,3 @@ app_name:views/en/datacenters/5bd92bd352e7726d02175752913014711f5d412e/companies
|
|
79
85
|
|
80
86
|
rm gemfiles/*.lock
|
81
87
|
bundle exec appraisal install
|
82
|
-
|
83
|
-
## TODO
|
84
|
-
|
85
|
-
- add coveralls
|
data/Rakefile
CHANGED
@@ -5,7 +5,7 @@ require 'appraisal'
|
|
5
5
|
require 'rspec/core/rake_task'
|
6
6
|
RSpec::Core::RakeTask.new(:spec)
|
7
7
|
|
8
|
-
task :default do
|
8
|
+
task :default do
|
9
9
|
if ENV['BUNDLE_GEMFILE'] =~ /gemfiles/
|
10
10
|
exec 'rake spec'
|
11
11
|
else
|
@@ -13,6 +13,6 @@ task :default do |t|
|
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
|
-
task :
|
16
|
+
task appraise: ['appraisal:install'] do
|
17
17
|
exec 'rake appraisal'
|
18
18
|
end
|
data/cache_key_for.gemspec
CHANGED
@@ -49,4 +49,10 @@ Gem::Specification.new do |s|
|
|
49
49
|
s.add_development_dependency('appraisal', '~> 1.0')
|
50
50
|
s.add_development_dependency('sqlite3', '~> 1.3')
|
51
51
|
s.add_development_dependency('rspec-rails', '~> 3.1')
|
52
|
+
s.add_development_dependency('coveralls', '~> 0.8.13')
|
53
|
+
s.add_development_dependency('simplecov', '~> 0.11.2')
|
54
|
+
s.add_development_dependency('pry', '~> 0.10.3')
|
55
|
+
s.add_development_dependency('pry-byebug', '~> 3.3.0')
|
56
|
+
s.add_development_dependency('fuubar', '~> 2.0.0')
|
57
|
+
s.add_development_dependency('codeclimate-test-reporter', '~> 0.5.0')
|
52
58
|
end
|
@@ -1,10 +1,16 @@
|
|
1
1
|
# Features:
|
2
|
-
# *
|
3
|
-
# *
|
4
|
-
# *
|
2
|
+
# * ORM agnostic
|
3
|
+
# * works with arrays and Plain Old Ruby Objects (POROs) (just provide: #id, #updated_at)
|
4
|
+
# * supports locale
|
5
|
+
# * recognizes subdomains
|
5
6
|
# * deletion from and addition to collections sorted in ascending order (via embedded `count` in the key)
|
6
7
|
# * accepts `cache_owner_cache_key` for personalized cache, eg. current_company.cache_key, current_user.cache_key etc.
|
7
|
-
# *
|
8
|
+
# * filters params with proper non-utf8 data handling for key generation
|
9
|
+
# * recognizes pagination via params (performs well for less than 100 objects per page)
|
10
|
+
# * includes all params, not only GET's `query` params, which enables submitting of complex forms via POST,
|
11
|
+
# which - otherwise - would have query string longer than 2048 characters (Microsoft Internet Explorer)
|
12
|
+
# * optional whitelist of first level parameters to prevent accidentally generating duplicated cache
|
13
|
+
# * strips utm_* params
|
8
14
|
# * optional suffix for:
|
9
15
|
# * expiry tags (unlike :expires_in cache option, this offers full :file_store storage compatibility)
|
10
16
|
# * any edge cases
|
@@ -35,12 +41,24 @@
|
|
35
41
|
# app_name:views/en/datacenters/5bd92bd352e7726d02175752913014711f5d412e/companies/1-20150619101645935901000/2015-06-26/7a6f89a738006a69c1d1e0214e147bab
|
36
42
|
# ```
|
37
43
|
module CacheKeyForHelper
|
38
|
-
def cache_key_for(scoped_collection, collection_prefix, cache_owner_cache_key = '', suffix = '')
|
39
|
-
max_updated_at = scoped_collection.to_a.map{|i| i.updated_at.
|
44
|
+
def cache_key_for(scoped_collection, collection_prefix, cache_owner_cache_key = '', suffix = '', whitelist_params = [])
|
45
|
+
max_updated_at = scoped_collection.to_a.map { |i| i.updated_at ? i.updated_at.utc.to_f : 0 }.max
|
40
46
|
count = scoped_collection.count
|
41
47
|
ids_string = scoped_collection.to_a.map(&:id).join('-')
|
42
|
-
|
43
|
-
|
48
|
+
blacklist_params = ['utm_source', 'utm_medium', 'utm_term', 'utm_content', 'utm_campaign']
|
49
|
+
request_params = if request.params
|
50
|
+
if whitelist_params.empty?
|
51
|
+
request.params.reject { |k, _v| blacklist_params.include?(k.to_s) }
|
52
|
+
else
|
53
|
+
request.params.select { |k, _v| whitelist_params.include?(k.to_s) }
|
54
|
+
end.map { |k, v| [k.to_s.dup.force_encoding('UTF-8'), v.dup.to_s.force_encoding('UTF-8')] }
|
55
|
+
else
|
56
|
+
nil
|
57
|
+
end
|
58
|
+
digest = Digest::SHA1.hexdigest("#{ids_string}-#{max_updated_at}-#{count}-#{request.subdomains.join('.')}-#{request.path}-#{request_params}")
|
59
|
+
# puts "Caller: #{caller.first}"
|
60
|
+
# puts "generated cache key digest base: #{ids_string}-#{max_updated_at}-#{count}-#{request.subdomains.join('.')}-#{request.path}-#{request_params}"
|
61
|
+
# puts "generated cache key: #{I18n.locale}/#{collection_prefix}/#{digest}/#{cache_owner_cache_key}/#{suffix}"
|
44
62
|
"#{I18n.locale}/#{collection_prefix}/#{digest}/#{cache_owner_cache_key}/#{suffix}"
|
45
63
|
end
|
46
64
|
end
|
@@ -16,7 +16,7 @@
|
|
16
16
|
# ```
|
17
17
|
module CacheKeyForViewHelper
|
18
18
|
include CacheKeyForHelper
|
19
|
-
def cache_key_for_view(file, scoped_collection, collection_prefix, cache_owner_cache_key = '', suffix = '')
|
20
|
-
"#{cache_key_for(scoped_collection, collection_prefix, cache_owner_cache_key, suffix)}#{file.gsub(Rails.root.to_s, '')}"
|
19
|
+
def cache_key_for_view(file, scoped_collection, collection_prefix, cache_owner_cache_key = '', suffix = '', whitelist_params = [])
|
20
|
+
"#{cache_key_for(scoped_collection, collection_prefix, cache_owner_cache_key, suffix, whitelist_params)}#{file.gsub(Rails.root.to_s, '')}"
|
21
21
|
end
|
22
22
|
end
|
@@ -2,11 +2,12 @@ require 'cache_key_for/cache_key_for_helper'
|
|
2
2
|
require 'cache_key_for/cache_key_for_view_helper'
|
3
3
|
|
4
4
|
module CacheKeyFor
|
5
|
+
#
|
5
6
|
class Railtie < Rails::Railtie
|
6
|
-
initializer 'cache_key_for.helper' do
|
7
|
+
initializer 'cache_key_for.helper' do
|
7
8
|
ActionView::Base.send :include, CacheKeyForHelper
|
8
9
|
end
|
9
|
-
initializer 'cache_key_for_view.helper' do
|
10
|
+
initializer 'cache_key_for_view.helper' do
|
10
11
|
ActionView::Base.send :include, CacheKeyForViewHelper
|
11
12
|
end
|
12
13
|
end
|
data/lib/cache_key_for.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cache_key_for
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marcin Kalita
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-04-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: appraisal
|
@@ -52,6 +52,90 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '3.1'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: coveralls
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.8.13
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.8.13
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: simplecov
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 0.11.2
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 0.11.2
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: pry
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 0.10.3
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 0.10.3
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: pry-byebug
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 3.3.0
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 3.3.0
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: fuubar
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 2.0.0
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: 2.0.0
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: codeclimate-test-reporter
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: 0.5.0
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: 0.5.0
|
55
139
|
description: How to design a perfect cache key? This project's goal is to provide
|
56
140
|
a bulletproof solution for most use cases.
|
57
141
|
email:
|