cache_sweeper 0.1.0 → 0.1.1
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 +4 -4
- data/README.md +2 -8
- data/lib/cache_sweeper/async_worker.rb +0 -7
- data/lib/cache_sweeper/flush_middleware.rb +0 -5
- data/lib/cache_sweeper/loader.rb +18 -26
- data/lib/cache_sweeper/version.rb +1 -1
- data/lib/cache_sweeper.rb +8 -11
- 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: a54fe370dd8641e18a0b8cfac9b09b8fbea6e3326a27c9f8e5a50fba9be2460d
|
4
|
+
data.tar.gz: b9dd405035a810f34a04c03d7d194448cc5096a843da3b160df6711d28708ce7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 42a5062112ae5d94ddc4a826be6d0fb369dc132dc05ebbc51f9bbc41027c740153197d58ce1063292d97ebcce563baf585a4063684e2b36d8f4f1e3336ef7d24
|
7
|
+
data.tar.gz: 797e2096794ea36294c54e29e752cbac48f5e964c6badb6d52a4bbaedd08ff0f824073e01e2814c6766c5c1b47c068741eedc1d3da1fa76f902a9a210bab6653
|
data/README.md
CHANGED
@@ -37,7 +37,7 @@ A flexible, rule-based cache invalidation gem for Rails applications. CacheSweep
|
|
37
37
|
Add this line to your application's Gemfile:
|
38
38
|
|
39
39
|
```ruby
|
40
|
-
gem 'cache_sweeper'
|
40
|
+
gem 'cache_sweeper'
|
41
41
|
```
|
42
42
|
|
43
43
|
Then run:
|
@@ -52,12 +52,6 @@ bundle install
|
|
52
52
|
- **Sidekiq**: Required for async cache deletion
|
53
53
|
- **RequestStore**: For thread-safe request-level storage
|
54
54
|
|
55
|
-
Add Sidekiq to your Gemfile:
|
56
|
-
|
57
|
-
```ruby
|
58
|
-
gem 'sidekiq'
|
59
|
-
gem 'request_store'
|
60
|
-
```
|
61
55
|
|
62
56
|
## Quick Start
|
63
57
|
|
@@ -583,4 +577,4 @@ MIT License. See [LICENSE.txt](LICENSE.txt) for details.
|
|
583
577
|
|
584
578
|
- [GitHub Repository](https://github.com/rafayqayyum/cache_sweeper)
|
585
579
|
- [MIT License](https://opensource.org/licenses/MIT)
|
586
|
-
- [RubyGems](https://rubygems.org/gems/cache_sweeper)
|
580
|
+
- [RubyGems](https://rubygems.org/gems/cache_sweeper)
|
@@ -57,13 +57,6 @@ module CacheSweeper
|
|
57
57
|
keys: Array(keys),
|
58
58
|
status: 'success'
|
59
59
|
})
|
60
|
-
when :rails_not_available
|
61
|
-
CacheSweeper::Logger.log_async_jobs("Rails cache not available for #{Array(keys).length} keys", :warn, {
|
62
|
-
job_id: jid,
|
63
|
-
keys_count: Array(keys).length,
|
64
|
-
keys: Array(keys),
|
65
|
-
status: 'rails_not_available'
|
66
|
-
})
|
67
60
|
when :error
|
68
61
|
CacheSweeper::Logger.log_error(error, {
|
69
62
|
job_id: jid,
|
@@ -102,11 +102,6 @@ class CacheSweeperFlushMiddleware
|
|
102
102
|
keys: Array(keys),
|
103
103
|
sidekiq_options: sidekiq_options
|
104
104
|
})
|
105
|
-
when :rails_not_available
|
106
|
-
CacheSweeper::Logger.log_middleware("Rails cache not available", :warn, {
|
107
|
-
request_id: request_id,
|
108
|
-
keys: Array(keys)
|
109
|
-
})
|
110
105
|
when :error
|
111
106
|
CacheSweeper::Logger.log_error(error, {
|
112
107
|
request_id: request_id,
|
data/lib/cache_sweeper/loader.rb
CHANGED
@@ -55,17 +55,12 @@ module CacheSweeper
|
|
55
55
|
request_key = "cache_sweeper_pending_keys_#{sweeper_name}"
|
56
56
|
keys = RequestStore.store[request_key]
|
57
57
|
if keys&.any?
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
failed_count = keys.length - deleted_count
|
65
|
-
else
|
66
|
-
deleted_count = 0
|
67
|
-
failed_count = keys.length
|
68
|
-
end
|
58
|
+
deleted_count = CacheSweeper.delete_cache_keys(keys, {
|
59
|
+
sweeper: sweeper_name,
|
60
|
+
mode: :inline,
|
61
|
+
trigger: :request
|
62
|
+
})
|
63
|
+
failed_count = keys.length - deleted_count
|
69
64
|
|
70
65
|
CacheSweeper::Logger.log_cache_operations("Flushed request-level keys", :info, {
|
71
66
|
sweeper: sweeper_name,
|
@@ -306,7 +301,7 @@ module CacheSweeper
|
|
306
301
|
})
|
307
302
|
|
308
303
|
begin
|
309
|
-
if trigger == :request
|
304
|
+
if trigger == :request && !in_console?
|
310
305
|
RequestStore.store[:cache_sweeper_request_pending] ||= []
|
311
306
|
RequestStore.store[:cache_sweeper_request_pending] << { keys: keys, mode: mode, sidekiq_options: sidekiq_opts }
|
312
307
|
CacheSweeper::Logger.log_cache_operations("Batched for request: #{Array(keys).inspect} (mode: #{mode})", :info, {
|
@@ -322,20 +317,13 @@ module CacheSweeper
|
|
322
317
|
sidekiq_options: sidekiq_opts
|
323
318
|
})
|
324
319
|
else
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
else
|
333
|
-
CacheSweeper::Logger.log_cache_operations("Rails cache not available for #{Array(keys).length} keys", :warn, {
|
334
|
-
keys: Array(keys)
|
335
|
-
})
|
336
|
-
deleted_count = 0
|
337
|
-
failed_count = Array(keys).length
|
338
|
-
end
|
320
|
+
|
321
|
+
deleted_count = CacheSweeper.delete_cache_keys(keys, {
|
322
|
+
sweeper: sweeper&.name,
|
323
|
+
mode: :inline,
|
324
|
+
trigger: :instant
|
325
|
+
})
|
326
|
+
failed_count = Array(keys).length - deleted_count
|
339
327
|
|
340
328
|
CacheSweeper::Logger.log_cache_operations("Instant deletion completed", :info, {
|
341
329
|
deleted_count: deleted_count,
|
@@ -364,5 +352,9 @@ module CacheSweeper
|
|
364
352
|
})
|
365
353
|
end
|
366
354
|
end
|
355
|
+
|
356
|
+
def self.in_console?
|
357
|
+
defined?(Rails::Console) || Rails.const_defined?('Console')
|
358
|
+
end
|
367
359
|
end
|
368
360
|
end
|
data/lib/cache_sweeper.rb
CHANGED
@@ -27,17 +27,14 @@ module CacheSweeper
|
|
27
27
|
|
28
28
|
def configure_defaults
|
29
29
|
DEFAULTS.each { |k, v| instance_variable_set("@#{k}", v) }
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
:info
|
39
|
-
end
|
40
|
-
end
|
30
|
+
@log_level =
|
31
|
+
if Rails.env.development?
|
32
|
+
:debug
|
33
|
+
elsif Rails.env.production?
|
34
|
+
:warn
|
35
|
+
else
|
36
|
+
:info
|
37
|
+
end
|
41
38
|
end
|
42
39
|
|
43
40
|
def log_level=(level)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cache_sweeper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rafay Qayyum
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-09-
|
11
|
+
date: 2025-09-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: request_store
|