prop 2.5.0 → 2.6.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.
- checksums.yaml +5 -5
- data/README.md +1 -1
- data/lib/prop.rb +1 -1
- data/lib/prop/interval_strategy.rb +4 -4
- data/lib/prop/leaky_bucket_strategy.rb +1 -1
- data/lib/prop/limiter.rb +1 -1
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: bf33dac797d0f3b3cf7126709f1622e3069b7cf476f0bfde211178b3e4e743e1
|
4
|
+
data.tar.gz: e166a98af608dab54400289bb8fd28738b4ba8ab18ee0604613e75907ae4ec5c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 953571f21e59adbbd743490543fa4a7faf30b0e07951f3646bf7e3af5043ed2e24d0f93c6c5d375b1bb866ed5719e1eefe206bf4ce230b5001d80a7fc0f48cee
|
7
|
+
data.tar.gz: ca8960bee3c4f2789d4ddc9a07e489ee646c45cbbe9391da6b76f7e06f81711224093806e60a49f85cd5f1451389868f22b58f1259283b33cf7ffad21665948b
|
data/README.md
CHANGED
@@ -18,7 +18,7 @@ To store values, prop needs a cache:
|
|
18
18
|
Prop.cache = Rails.cache # needs read/write/increment methods
|
19
19
|
```
|
20
20
|
|
21
|
-
|
21
|
+
When using the interval strategy, prop sets a key expiry to its interval. Because the leaky bucket strategy does not set a ttl, it is best to use memcached or similar for all prop caching, not redis.
|
22
22
|
|
23
23
|
## Setting a Callback
|
24
24
|
|
data/lib/prop.rb
CHANGED
@@ -16,16 +16,16 @@ module Prop
|
|
16
16
|
# options argument is kept for api consistency for all strategies
|
17
17
|
def increment(cache_key, amount, options = {})
|
18
18
|
raise ArgumentError, "Change amount must be a Integer, was #{amount.class}" unless amount.is_a?(Integer)
|
19
|
-
cache.increment(cache_key, amount) || (cache.write(cache_key, amount, raw: true) && amount) # WARNING: potential race condition
|
19
|
+
cache.increment(cache_key, amount) || (cache.write(cache_key, amount, raw: true, expires_in: options.fetch(:interval, nil)) && amount) # WARNING: potential race condition
|
20
20
|
end
|
21
21
|
|
22
22
|
def decrement(cache_key, amount, options = {})
|
23
23
|
raise ArgumentError, "Change amount must be a Integer, was #{amount.class}" unless amount.is_a?(Integer)
|
24
|
-
cache.decrement(cache_key, amount) || (cache.write(cache_key, 0, raw: true) && 0) # WARNING: potential race condition
|
24
|
+
cache.decrement(cache_key, amount) || (cache.write(cache_key, 0, raw: true, expires_in: options.fetch(:interval, nil)) && 0) # WARNING: potential race condition
|
25
25
|
end
|
26
26
|
|
27
|
-
def reset(cache_key)
|
28
|
-
cache.write(cache_key, zero_counter, raw: true)
|
27
|
+
def reset(cache_key, options = {})
|
28
|
+
cache.write(cache_key, zero_counter, raw: true, expires_in: options.fetch(:interval, nil))
|
29
29
|
end
|
30
30
|
|
31
31
|
def compare_threshold?(counter, operator, options)
|
data/lib/prop/limiter.rb
CHANGED
@@ -120,7 +120,7 @@ module Prop
|
|
120
120
|
# Returns nothing
|
121
121
|
def reset(handle, key = nil, options = {})
|
122
122
|
_options, cache_key, strategy = prepare(handle, key, options)
|
123
|
-
strategy.reset(cache_key)
|
123
|
+
strategy.reset(cache_key, options)
|
124
124
|
end
|
125
125
|
|
126
126
|
# Public: Counts the number of times the given handle/key combination has been hit in the current window
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: prop
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Morten Primdahl
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-08-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -115,8 +115,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
115
115
|
- !ruby/object:Gem::Version
|
116
116
|
version: '0'
|
117
117
|
requirements: []
|
118
|
-
|
119
|
-
rubygems_version: 2.6.14
|
118
|
+
rubygems_version: 3.1.6
|
120
119
|
signing_key:
|
121
120
|
specification_version: 4
|
122
121
|
summary: Gem for implementing rate limits.
|