rails-fast-cache 0.0.1 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rails-fast-cache/non_serializing_job.rb +3 -0
- data/lib/rails-fast-cache/scheduler.rb +20 -0
- data/lib/rails-fast-cache/store.rb +21 -16
- data/lib/rails-fast-cache/version.rb +1 -1
- data/lib/rails-fast-cache/write_job.rb +2 -2
- data/lib/rails-fast-cache/write_multi_job.rb +2 -2
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ca141bb50fad8045f8dd6c9e47a75bca1cebc3c753189bb376eb9bc3fd0ac784
|
4
|
+
data.tar.gz: c6b28ef4c1bb3ee5702a4904faaad71f783d602bbda2e79bdc6d8c20391a6eff
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3e2ffd591f426ee5ee7edb136ec3cb1fa692601a6804942a9774125ae9389113d13d23297adb3ed1b2be2b924d8f798fe1ae0152ddec193963ea467c0f53dc56
|
7
|
+
data.tar.gz: 37fc88731af7baa47967f53db7cc4cccc53a64555f00f1df65348b51888a793951d3d8cd1e2d5d92e531246a2475e47a352a7358f09f033ac85567ef99214ce7
|
@@ -1,10 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'active_job'
|
4
|
+
require_relative 'scheduler'
|
4
5
|
|
5
6
|
module RailsFastCache
|
6
7
|
class NonSerializingJob < ::ActiveJob::Base
|
7
8
|
self.logger = nil
|
9
|
+
self.log_arguments = false
|
10
|
+
self.queue_adapter = RailsFastCache::Scheduler.queue_adapter
|
8
11
|
|
9
12
|
def deserialize_arguments(serialized_arguments)
|
10
13
|
serialized_arguments
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RailsFastCache
|
4
|
+
class Scheduler
|
5
|
+
EXECUTOR_OPTIONS = {
|
6
|
+
min_threads: ENV.fetch('RAILS_MAX_THREADS', 3).to_i,
|
7
|
+
max_threads: ENV.fetch('RAILS_MAX_THREADS', 3).to_i,
|
8
|
+
max_queue: 100,
|
9
|
+
fallback_policy: :caller_runs
|
10
|
+
}.freeze
|
11
|
+
|
12
|
+
def self.queue_adapter
|
13
|
+
@queue_adapter ||= ActiveJob::QueueAdapters::AsyncAdapter.new(**EXECUTOR_OPTIONS)
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.shutdown
|
17
|
+
@queue_adapter&.shutdown(wait: true)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -5,18 +5,12 @@ require 'active_support'
|
|
5
5
|
require 'active_support/core_ext'
|
6
6
|
|
7
7
|
require_relative 'brotli_compressor'
|
8
|
+
require_relative 'scheduler'
|
8
9
|
require_relative 'write_job'
|
9
10
|
require_relative 'write_multi_job'
|
10
11
|
|
11
12
|
module RailsFastCache
|
12
13
|
class Store < ::ActiveSupport::Cache::Store
|
13
|
-
DEFAULT_EXECUTOR_OPTIONS = {
|
14
|
-
min_threads: ENV.fetch('RAILS_MAX_THREADS', 3).to_i,
|
15
|
-
max_threads: ENV.fetch('RAILS_MAX_THREADS', 3).to_i,
|
16
|
-
max_queue: 100,
|
17
|
-
fallback_policy: :caller_runs
|
18
|
-
}.freeze
|
19
|
-
|
20
14
|
delegate(
|
21
15
|
:cleanup,
|
22
16
|
:clear,
|
@@ -34,30 +28,41 @@ module RailsFastCache
|
|
34
28
|
:read,
|
35
29
|
:read_multi,
|
36
30
|
:silence!,
|
37
|
-
to: :@
|
31
|
+
to: :@cache_store
|
38
32
|
)
|
33
|
+
delegate_missing_to :@cache_store
|
34
|
+
|
35
|
+
cattr_accessor :cache_store
|
36
|
+
|
37
|
+
def self.supports_cache_versioning?
|
38
|
+
true
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.shutdown
|
42
|
+
RailsFastCache::Scheduler.shutdown
|
43
|
+
end
|
39
44
|
|
40
45
|
def initialize(cache_store, *parameters)
|
41
46
|
options = parameters.extract_options!
|
42
47
|
options[:compressor] ||= RailsFastCache::BrotliCompressor if !options.key?(:coder) && cache_store != :memory_store
|
43
48
|
options[:serializer] ||= :message_pack unless options.key?(:coder)
|
44
49
|
|
45
|
-
@
|
46
|
-
|
47
|
-
)
|
48
|
-
@store = ActiveSupport::Cache.lookup_store(cache_store, *parameters, **options)
|
50
|
+
@cache_store = ActiveSupport::Cache.lookup_store(cache_store, *parameters, **options)
|
51
|
+
self.class.cache_store = @cache_store
|
49
52
|
end
|
50
53
|
|
51
54
|
def write(name, value, options = nil)
|
52
|
-
|
55
|
+
WriteJob.perform_later(@cache_store, name, value, options)
|
56
|
+
true
|
53
57
|
end
|
54
58
|
|
55
59
|
def write_multi(hash, options = nil)
|
56
|
-
|
60
|
+
WriteMultiJob.perform_later(@cache_store, hash, options)
|
61
|
+
true
|
57
62
|
end
|
58
63
|
|
59
|
-
def shutdown
|
60
|
-
|
64
|
+
def shutdown
|
65
|
+
self.class.shutdown
|
61
66
|
end
|
62
67
|
end
|
63
68
|
end
|
@@ -4,8 +4,8 @@ require_relative 'non_serializing_job'
|
|
4
4
|
|
5
5
|
module RailsFastCache
|
6
6
|
class WriteJob < NonSerializingJob
|
7
|
-
def perform(
|
8
|
-
|
7
|
+
def perform(cache_store, name, value, options)
|
8
|
+
cache_store.write(name, value, options)
|
9
9
|
end
|
10
10
|
end
|
11
11
|
end
|
@@ -4,8 +4,8 @@ require_relative 'non_serializing_job'
|
|
4
4
|
|
5
5
|
module RailsFastCache
|
6
6
|
class WriteMultiJob < NonSerializingJob
|
7
|
-
def perform(
|
8
|
-
|
7
|
+
def perform(cache_store, hash, options)
|
8
|
+
cache_store.write_multi(hash, options)
|
9
9
|
end
|
10
10
|
end
|
11
11
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails-fast-cache
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Filippo Liverani
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-02
|
11
|
+
date: 2024-09-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activejob
|
@@ -120,6 +120,7 @@ files:
|
|
120
120
|
- lib/rails-fast-cache.rb
|
121
121
|
- lib/rails-fast-cache/brotli_compressor.rb
|
122
122
|
- lib/rails-fast-cache/non_serializing_job.rb
|
123
|
+
- lib/rails-fast-cache/scheduler.rb
|
123
124
|
- lib/rails-fast-cache/store.rb
|
124
125
|
- lib/rails-fast-cache/version.rb
|
125
126
|
- lib/rails-fast-cache/write_job.rb
|
@@ -146,7 +147,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
146
147
|
- !ruby/object:Gem::Version
|
147
148
|
version: '0'
|
148
149
|
requirements: []
|
149
|
-
rubygems_version: 3.5.
|
150
|
+
rubygems_version: 3.5.18
|
150
151
|
signing_key:
|
151
152
|
specification_version: 4
|
152
153
|
summary: Drop-in improvement for Rails cache, providing enhanced performance with
|