cache_key_for 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +2 -2
- data/README.md +1 -0
- data/lib/cache_key_for/cache_key_for_helper.rb +4 -3
- data/lib/cache_key_for/version.rb +1 -1
- 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: b63791dd91d36103f05b7ed05d2277a2930e0e23
|
4
|
+
data.tar.gz: e2099e762d0e2a37064ad55f5544431c190297ff
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 51ed14279d471dfcd0285d6a7504fbfd487ce6dcb86bfa696c3f16c8a236b1dcecd433eec1a0578fe762f387c0b4e070df85c0e1f879debbc56db3101aaf53f0
|
7
|
+
data.tar.gz: 0b2d4b9d7dab90f686c152429799d16020306fc604bc7ef4570ff2d73f995723f634d8ce604b20263744ca454e095185f6639f59c47a23f7f5e7259da42ffa0b
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -22,6 +22,7 @@ Features:
|
|
22
22
|
* accepts `cache_owner_cache_key` for personalized cache, eg. current_company.cache_key, current_user.cache_key etc.
|
23
23
|
* filters params with proper non-utf8 data handling for key generation
|
24
24
|
* recognizes pagination via params (performs well for less than 100 objects per page)
|
25
|
+
* allows to set default page and per_page or sort order or any param in `default_params` to avoid multiple different default caches
|
25
26
|
* includes all params, not only GET's `query` params, which enables submitting of complex forms via POST,
|
26
27
|
which - otherwise - would have query string longer than 2048 characters (Microsoft Internet Explorer)
|
27
28
|
* optional whitelist of first level parameters to prevent accidentally generating duplicated cache
|
@@ -7,6 +7,7 @@
|
|
7
7
|
# * accepts `cache_owner_cache_key` for personalized cache, eg. current_company.cache_key, current_user.cache_key etc.
|
8
8
|
# * filters params with proper non-utf8 data handling for key generation
|
9
9
|
# * recognizes pagination via params (performs well for less than 100 objects per page)
|
10
|
+
# * allows to set default page and per_page or sort order or any param in `default_params` to avoid multiple different default caches
|
10
11
|
# * includes all params, not only GET's `query` params, which enables submitting of complex forms via POST,
|
11
12
|
# which - otherwise - would have query string longer than 2048 characters (Microsoft Internet Explorer)
|
12
13
|
# * optional whitelist of first level parameters to prevent accidentally generating duplicated cache
|
@@ -41,16 +42,16 @@
|
|
41
42
|
# app_name:views/en/datacenters/5bd92bd352e7726d02175752913014711f5d412e/companies/1-20150619101645935901000/2015-06-26/7a6f89a738006a69c1d1e0214e147bab
|
42
43
|
# ```
|
43
44
|
module CacheKeyForHelper
|
44
|
-
def cache_key_for(scoped_collection, collection_prefix, cache_owner_cache_key = '', suffix = '', whitelist_params = [])
|
45
|
+
def cache_key_for(scoped_collection, collection_prefix, cache_owner_cache_key = '', suffix = '', whitelist_params = [], default_params = {})
|
45
46
|
max_updated_at = scoped_collection.to_a.map { |i| i.updated_at ? i.updated_at.utc.to_f : 0 }.max
|
46
47
|
count = scoped_collection.count
|
47
48
|
ids_string = scoped_collection.to_a.map(&:id).join('-')
|
48
49
|
blacklist_params = ['utm_source', 'utm_medium', 'utm_term', 'utm_content', 'utm_campaign']
|
49
50
|
request_params = if request.params
|
50
51
|
if whitelist_params.empty?
|
51
|
-
request.params.reject { |k, _v| blacklist_params.include?(k.to_s) }
|
52
|
+
default_params.merge(request.params).reject { |k, _v| blacklist_params.include?(k.to_s) }
|
52
53
|
else
|
53
|
-
request.params.select { |k, _v| whitelist_params.include?(k.to_s) }
|
54
|
+
default_params.merge(request.params).select { |k, _v| whitelist_params.include?(k.to_s) }
|
54
55
|
end.map { |k, v| [k.to_s.dup.force_encoding('UTF-8'), v.dup.to_s.force_encoding('UTF-8')] }
|
55
56
|
else
|
56
57
|
nil
|
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.3
|
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-05-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: appraisal
|