rails-fast-cache 0.0.1 → 1.0.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 +20 -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: bfbdf0aa8ac3d10ddc76b42c8beef628bb252fbdb4d1e9763e82c90f34e9e02d
|
4
|
+
data.tar.gz: 92c598e15a421e638456ff78d9ed76db83d09b990dce76d5b2b8ca9846f8feb1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aa52c7bad3217ff404d54d7799370c1f29059a8a76da44595b2e065f7f42203a9c108eebd37e01f4626d63101a9448de80ea67a61197784ad9efa4aef01265cc
|
7
|
+
data.tar.gz: 1f41fc618e9762686ed050529bb0982334c81f04255c96c2fe4f78870c40cb22fd1db3b24a1818030f0b173b972f5d10c3d9939eb473205b7f02ab7815343cd2
|
@@ -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,40 @@ module RailsFastCache
|
|
34
28
|
:read,
|
35
29
|
:read_multi,
|
36
30
|
:silence!,
|
37
|
-
to: :@
|
31
|
+
to: :@cache_store
|
38
32
|
)
|
39
33
|
|
34
|
+
cattr_accessor :cache_store
|
35
|
+
|
36
|
+
def self.supports_cache_versioning?
|
37
|
+
true
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.shutdown
|
41
|
+
RailsFastCache::Scheduler.shutdown
|
42
|
+
end
|
43
|
+
|
40
44
|
def initialize(cache_store, *parameters)
|
41
45
|
options = parameters.extract_options!
|
42
46
|
options[:compressor] ||= RailsFastCache::BrotliCompressor if !options.key?(:coder) && cache_store != :memory_store
|
43
47
|
options[:serializer] ||= :message_pack unless options.key?(:coder)
|
44
48
|
|
45
|
-
@
|
46
|
-
|
47
|
-
)
|
48
|
-
@store = ActiveSupport::Cache.lookup_store(cache_store, *parameters, **options)
|
49
|
+
@cache_store = ActiveSupport::Cache.lookup_store(cache_store, *parameters, **options)
|
50
|
+
self.class.cache_store = @cache_store
|
49
51
|
end
|
50
52
|
|
51
53
|
def write(name, value, options = nil)
|
52
|
-
|
54
|
+
WriteJob.perform_later(@cache_store,name, value, options)
|
55
|
+
true
|
53
56
|
end
|
54
57
|
|
55
58
|
def write_multi(hash, options = nil)
|
56
|
-
|
59
|
+
WriteMultiJob.perform_later(@cache_store, hash, options)
|
60
|
+
true
|
57
61
|
end
|
58
62
|
|
59
|
-
def shutdown
|
60
|
-
|
63
|
+
def shutdown
|
64
|
+
self.class.shutdown
|
61
65
|
end
|
62
66
|
end
|
63
67
|
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: 0.0
|
4
|
+
version: 1.0.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-
|
11
|
+
date: 2024-07-05 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.14
|
150
151
|
signing_key:
|
151
152
|
specification_version: 4
|
152
153
|
summary: Drop-in improvement for Rails cache, providing enhanced performance with
|