rack-cache 1.10.0 → 1.11.0

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.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGES +9 -0
  3. data/README.md +14 -2
  4. data/lib/rack/cache/key.rb +21 -5
  5. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c3812540d0f5bbe2e962a141bfec32689f6fd91eba903f450bacca8b7ba3ac8e
4
- data.tar.gz: e688349a29392080fdf0e906f262675bff93af5831336370ef5a2b88aa5838ac
3
+ metadata.gz: 7e2ca34b16edeb06ab8ce7df32ad78b273b600cd950ce3b56d03b898bf00e53f
4
+ data.tar.gz: 5d35c87987859feb36e5f24b3b065ac790c6dc4f3df0969e41aaa6f15819ab94
5
5
  SHA512:
6
- metadata.gz: f411e9b9678e5e3d4c80623a0d2bede18b2f024ed9e8d7e9d78e114f3fb69278f46ca2cf2281e9ca7260a4a4f3c6225f8ebbc8116aabb5ffa4b2ba8e6ceb6d20
7
- data.tar.gz: 51105145c2d3fb9c9106bb77e71254f002e416a0978f1a0d788e674ba73ba87645c387c86b875b4c7973ba32f6a1cb89f35e8c1102904e1258d3f91060a929e0
6
+ metadata.gz: 1d156a65178883329c11d00024f60af8d013cd4fe2a3def6d930c43d822c76dd1bd9b6d26d965209fbfdc038e79cff96a5efd973deadace39e0b83097c332ec5
7
+ data.tar.gz: 9a3b6fdc70f24de95a8cc02d3d9180c5c59f277156605ddca2b295e56542f81b0433fb8da279d0f337d49d4352e0e2500be4a468fc75a61c5b13eadccf1b3cc7
data/CHANGES CHANGED
@@ -1,3 +1,12 @@
1
+ ## 1.11.0
2
+
3
+ * Add a proc to allow ignoring parts of the query string in the key
4
+
5
+ ## 1.10.0
6
+
7
+ * Pass Options To Underlying Storage Driver
8
+ * bump required ruby version to 2.3
9
+
1
10
  ## 1.9.0
2
11
 
3
12
  * make purge not raise when not implemented
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
-
@@ -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
- map { |p| p.split('=', 2).map{ |s| unescape(s) } }.
47
- sort.
48
- map { |k,v| "#{escape(k)}=#{escape(v)}" }.
49
- join('&')
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.10.0
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: 2019-11-06 00:00:00.000000000 Z
11
+ date: 2020-01-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack