rack-cache 1.10.0 → 1.11.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES +9 -0
- data/README.md +14 -2
- data/lib/rack/cache/key.rb +21 -5
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7e2ca34b16edeb06ab8ce7df32ad78b273b600cd950ce3b56d03b898bf00e53f
|
4
|
+
data.tar.gz: 5d35c87987859feb36e5f24b3b065ac790c6dc4f3df0969e41aaa6f15819ab94
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1d156a65178883329c11d00024f60af8d013cd4fe2a3def6d930c43d822c76dd1bd9b6d26d965209fbfdc038e79cff96a5efd973deadace39e0b83097c332ec5
|
7
|
+
data.tar.gz: 9a3b6fdc70f24de95a8cc02d3d9180c5c59f277156605ddca2b295e56542f81b0433fb8da279d0f337d49d4352e0e2500be4a468fc75a61c5b13eadccf1b3cc7
|
data/CHANGES
CHANGED
data/README.md
CHANGED
@@ -97,7 +97,7 @@ Does not persist response bodies (no disk/memory used).<br/>
|
|
97
97
|
Responses from the cache will have an empty body.<br/>
|
98
98
|
Clients must ignore these empty cached response (check for X-Rack-Cache response header).<br/>
|
99
99
|
Atm cannot handle streamed responses, patch needed.
|
100
|
-
|
100
|
+
|
101
101
|
```Ruby
|
102
102
|
require 'rack/cache'
|
103
103
|
|
@@ -109,6 +109,18 @@ use Rack::Cache,
|
|
109
109
|
run app
|
110
110
|
```
|
111
111
|
|
112
|
+
Ignoring tracking parameters in cache keys
|
113
|
+
-----------------
|
114
|
+
|
115
|
+
It's fairly common to include tracking parameters which don't affect the content
|
116
|
+
of the page. Since Rack::Cache uses the full URL as part of the cache key, this
|
117
|
+
can cause unneeded churn in your cache. If you're using the default key class
|
118
|
+
`Rack::Cache::Key`, you can configure a proc to ignore certain keys/values like
|
119
|
+
so:
|
120
|
+
|
121
|
+
```Ruby
|
122
|
+
Rack::Cache::Key.query_string_ignore = proc { |k, v| k =~ /^(trk|utm)_/ }
|
123
|
+
```
|
124
|
+
|
112
125
|
License: MIT<br/>
|
113
126
|
[![Build Status](https://travis-ci.org/rtomayko/rack-cache.svg)](https://travis-ci.org/rtomayko/rack-cache)
|
114
|
-
|
data/lib/rack/cache/key.rb
CHANGED
@@ -4,6 +4,21 @@ module Rack::Cache
|
|
4
4
|
class Key
|
5
5
|
include Rack::Utils
|
6
6
|
|
7
|
+
# A proc for ignoring parts of query strings when generating a key. This is
|
8
|
+
# useful when you have parameters like `utm` or `trk` that don't affect the
|
9
|
+
# content on the page and are unique per-visitor or campaign. Parameters
|
10
|
+
# like these will be part of the key and cause a lot of churn.
|
11
|
+
#
|
12
|
+
# The block will be passed a key and value which are the name and value of
|
13
|
+
# that parameter.
|
14
|
+
#
|
15
|
+
# Example:
|
16
|
+
# `Rack::Cache::Key.query_string_ignore = proc { |k, v| k =~ /^(trk|utm)_/ }`
|
17
|
+
#
|
18
|
+
class << self
|
19
|
+
attr_accessor :query_string_ignore
|
20
|
+
end
|
21
|
+
|
7
22
|
# Implement .call, since it seems like the "Rack-y" thing to do. Plus, it
|
8
23
|
# opens the door for cache key generators to just be blocks.
|
9
24
|
def self.call(request)
|
@@ -42,11 +57,12 @@ module Rack::Cache
|
|
42
57
|
def query_string
|
43
58
|
return nil if @request.query_string.to_s.empty?
|
44
59
|
|
45
|
-
@request.query_string.split(/[&;] */n)
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
60
|
+
parts = @request.query_string.split(/[&;] */n)
|
61
|
+
parts.map! { |p| p.split('=', 2).map!{ |s| unescape(s) } }
|
62
|
+
parts.sort!
|
63
|
+
parts.reject!(&self.class.query_string_ignore)
|
64
|
+
parts.map! { |k,v| "#{escape(k)}=#{escape(v)}" }
|
65
|
+
parts.join('&')
|
50
66
|
end
|
51
67
|
end
|
52
68
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-cache
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.11.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan Tomayko
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-01-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|