safe_memoize 1.1.0 → 1.3.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 +4 -4
- data/.github/workflows/ci.yml +2 -2
- data/CHANGELOG.md +57 -1
- data/README.md +584 -6
- data/ROADMAP.md +0 -30
- data/Rakefile +9 -5
- data/lib/safe_memoize/adapters/concurrent_ruby.rb +98 -0
- data/lib/safe_memoize/cache_metrics_methods.rb +4 -5
- data/lib/safe_memoize/class_methods.rb +330 -23
- data/lib/safe_memoize/configuration.rb +8 -0
- data/lib/safe_memoize/custom_key_methods.rb +11 -2
- data/lib/safe_memoize/extension.rb +88 -0
- data/lib/safe_memoize/fiber_local_methods.rb +109 -0
- data/lib/safe_memoize/hooks_methods.rb +8 -1
- data/lib/safe_memoize/inspection_methods.rb +34 -5
- data/lib/safe_memoize/instance_methods.rb +1 -0
- data/lib/safe_memoize/public_methods.rb +3 -2
- data/lib/safe_memoize/public_metrics_methods.rb +4 -3
- data/lib/safe_memoize/ractor_shared_methods.rb +146 -0
- data/lib/safe_memoize/release_tooling.rb +25 -0
- data/lib/safe_memoize/version.rb +1 -1
- data/lib/safe_memoize.rb +141 -0
- data/sig/safe_memoize.rbs +77 -2
- metadata +5 -1
data/sig/safe_memoize.rbs
CHANGED
|
@@ -18,11 +18,36 @@ module SafeMemoize
|
|
|
18
18
|
@__safe_memo_shared_mutex__: Mutex?
|
|
19
19
|
@__safe_memo_shared_lru_order__: Hash[Symbol, Hash[memo_key, true]]?
|
|
20
20
|
|
|
21
|
+
SHARED_CACHE_REGISTRY: Hash[String, Stores::Base]
|
|
22
|
+
SHARED_CACHE_MUTEX: Mutex
|
|
23
|
+
EXTENSION_REGISTRY: Hash[Symbol, untyped]
|
|
24
|
+
EXTENSION_MUTEX: Mutex
|
|
25
|
+
|
|
21
26
|
def self.prepended: (Class base) -> void
|
|
22
27
|
def self.configure: () { (Configuration) -> void } -> void
|
|
23
28
|
def self.configuration: () -> Configuration
|
|
24
29
|
def self.reset_configuration!: () -> Configuration
|
|
25
30
|
def self.deprecate: (String subject, message: String, horizon: String) -> void
|
|
31
|
+
def self.shared_cache: (String name) -> Stores::Base
|
|
32
|
+
def self.register_shared_cache: (String name, Stores::Base store) -> Stores::Base
|
|
33
|
+
def self.clear_shared_cache: (String name) -> void
|
|
34
|
+
def self.drop_shared_cache: (String name) -> Stores::Base?
|
|
35
|
+
def self.shared_caches: () -> Hash[String, Stores::Base]
|
|
36
|
+
def self.reset_shared_caches!: () -> void
|
|
37
|
+
def self.register_extension: (Symbol | String name, untyped extension) -> untyped
|
|
38
|
+
def self.unregister_extension: (Symbol | String name) -> untyped?
|
|
39
|
+
def self.extensions: () -> Hash[Symbol, untyped]
|
|
40
|
+
def self.reset_extensions!: () -> void
|
|
41
|
+
def self.extension_for_option: (Symbol option_name) -> untyped?
|
|
42
|
+
def self.dispatch_extension_events: (Symbol event_type, Class klass, Symbol method_name, untyped cache_key, untyped record) -> void
|
|
43
|
+
|
|
44
|
+
module Extension
|
|
45
|
+
def handles_option: (Symbol option_name) { (untyped value, Symbol method_name, Hash[Symbol, untyped] all_options) -> Hash[Symbol, untyped]? } -> void
|
|
46
|
+
def on_cache_event: (*Symbol event_types) { (Class klass, Symbol method_name, untyped cache_key, untyped record) -> void } -> void
|
|
47
|
+
def handled_options: () -> Array[Symbol]
|
|
48
|
+
def process_memoize_option: (Symbol option_name, untyped value, Symbol method_name, Hash[Symbol, untyped] all_options) -> Hash[Symbol, untyped]
|
|
49
|
+
def dispatch_cache_event: (Symbol event_type, Class klass, Symbol method_name, untyped cache_key, untyped record) -> void
|
|
50
|
+
end
|
|
26
51
|
|
|
27
52
|
class Configuration
|
|
28
53
|
attr_accessor default_ttl: Numeric?
|
|
@@ -33,13 +58,18 @@ module SafeMemoize
|
|
|
33
58
|
attr_accessor statsd_client: untyped
|
|
34
59
|
attr_accessor opentelemetry_tracer: untyped
|
|
35
60
|
attr_accessor default_store: Stores::Base?
|
|
61
|
+
attr_accessor namespace: String?
|
|
36
62
|
|
|
37
63
|
def initialize: () -> void
|
|
38
64
|
end
|
|
39
65
|
|
|
40
66
|
module ClassMethods
|
|
41
|
-
def memoize: (Symbol | String method_name, ?ttl: Numeric?, ?max_size: Integer?, ?ttl_refresh: bool, ?if: (^(untyped result) -> boolish)?, ?unless: (^(untyped result) -> boolish)?, ?shared: bool, ?key: (^(*untyped args, **untyped kwargs) -> untyped)?, ?store: Stores::Base?) -> void
|
|
42
|
-
def
|
|
67
|
+
def memoize: (Symbol | String method_name, ?ttl: Numeric?, ?max_size: Integer?, ?ttl_refresh: bool, ?if: (^(untyped result) -> boolish)?, ?unless: (^(untyped result) -> boolish)?, ?shared: bool, ?key: (^(*untyped args, **untyped kwargs) -> untyped)?, ?store: Stores::Base?, ?fiber_local: bool, ?ractor_safe: bool, ?namespace: String?, ?shared_cache: String?, ?cache_bust: (^() -> untyped) | Symbol | nil, **untyped extension_options) -> void
|
|
68
|
+
def safe_memoize_store: () -> Stores::Base?
|
|
69
|
+
def safe_memoize_store=: (Stores::Base?) -> Stores::Base?
|
|
70
|
+
def safe_memoize_namespace: () -> String?
|
|
71
|
+
def safe_memoize_namespace=: (String?) -> String?
|
|
72
|
+
def memoize_all: (?except: Array[Symbol | String], ?only: Array[Symbol | String], ?include_protected: bool, ?include_private: bool, ?ttl: Numeric?, ?max_size: Integer?, ?if: (^(untyped result) -> boolish)?, ?unless: (^(untyped result) -> boolish)?, ?shared: bool, ?key: (^(*untyped args, **untyped kwargs) -> untyped)?, ?fiber_local: bool, ?namespace: String?, ?shared_cache: String?) -> void
|
|
43
73
|
def reset_shared_memo: (Symbol | String method_name, *untyped args, **untyped kwargs) -> void
|
|
44
74
|
def reset_all_shared_memos: () -> void
|
|
45
75
|
def shared_memoized?: (Symbol | String method_name, *untyped args, **untyped kwargs) -> bool
|
|
@@ -53,6 +83,8 @@ module SafeMemoize
|
|
|
53
83
|
def __safe_memo_shared_mutex__: () -> Mutex
|
|
54
84
|
def __safe_memo_shared_lru_order__: () -> Hash[Symbol, Hash[memo_key, true]]
|
|
55
85
|
def __safe_memo_class_key_generators__: () -> Hash[Symbol, Proc]
|
|
86
|
+
def __safe_memo_method_namespaces__: () -> Hash[Symbol, String]
|
|
87
|
+
def __safe_memo_class_cache_bust_generators__: () -> Hash[Symbol, Proc | Symbol]
|
|
56
88
|
def memoized_method_visibility: (Symbol method_name) -> Symbol
|
|
57
89
|
end
|
|
58
90
|
|
|
@@ -187,6 +219,37 @@ module SafeMemoize
|
|
|
187
219
|
def lru_clear_all: () -> void
|
|
188
220
|
end
|
|
189
221
|
|
|
222
|
+
module FiberLocalMethods
|
|
223
|
+
FIBER_STORE_KEY: Symbol
|
|
224
|
+
|
|
225
|
+
def fiber_local_memoized?: (Symbol | String method_name, *untyped args, **untyped kwargs) ?{ () -> untyped } -> bool
|
|
226
|
+
def reset_fiber_memo: (Symbol | String method_name, *untyped args, **untyped kwargs) -> void
|
|
227
|
+
def reset_all_fiber_memos: () -> void
|
|
228
|
+
|
|
229
|
+
private
|
|
230
|
+
|
|
231
|
+
def fiber_root_store!: () -> Hash[untyped, untyped]
|
|
232
|
+
def fiber_memo_store!: () -> { cache: Hash[memo_key, memo_record], lru: Hash[Symbol, Hash[memo_key, true]] }
|
|
233
|
+
def fiber_memo_cache!: () -> Hash[memo_key, memo_record]
|
|
234
|
+
def fiber_memo_lru!: () -> Hash[Symbol, Hash[memo_key, true]]
|
|
235
|
+
def fiber_root_store_or_nil: () -> Hash[untyped, untyped]?
|
|
236
|
+
def fiber_memo_store_or_nil: () -> { cache: Hash[memo_key, memo_record], lru: Hash[Symbol, Hash[memo_key, true]] }?
|
|
237
|
+
def fiber_memo_cache_or_nil: () -> Hash[memo_key, memo_record]?
|
|
238
|
+
def fiber_memo_lru_or_nil: () -> Hash[Symbol, Hash[memo_key, true]]?
|
|
239
|
+
end
|
|
240
|
+
|
|
241
|
+
module RactorSharedMethods
|
|
242
|
+
def reset_ractor_memo: (Symbol | String method_name, *untyped args, **untyped kwargs) -> void
|
|
243
|
+
def reset_all_ractor_memos: () -> void
|
|
244
|
+
def ractor_memoized?: (Symbol | String method_name, *untyped args, **untyped kwargs) -> bool
|
|
245
|
+
def ractor_memo_count: (?(Symbol | String) method_name) -> Integer
|
|
246
|
+
|
|
247
|
+
private
|
|
248
|
+
|
|
249
|
+
def __ractor_cache_send__: (untyped supervisor, Symbol op, *untyped args) -> untyped
|
|
250
|
+
def __safe_memo_ractor_supervisor__: () -> untyped
|
|
251
|
+
end
|
|
252
|
+
|
|
190
253
|
module InstanceMethods
|
|
191
254
|
include PublicMethods
|
|
192
255
|
include CacheStoreMethods
|
|
@@ -198,6 +261,7 @@ module SafeMemoize
|
|
|
198
261
|
include CustomKeyMethods
|
|
199
262
|
include PublicCustomKeyMethods
|
|
200
263
|
include LruMethods
|
|
264
|
+
include FiberLocalMethods
|
|
201
265
|
end
|
|
202
266
|
|
|
203
267
|
module Stores
|
|
@@ -237,6 +301,17 @@ module SafeMemoize
|
|
|
237
301
|
SPAN_NAME: String
|
|
238
302
|
def self.trace: (untyped tracer, Symbol | String method_name, String? class_name) { () -> untyped } -> untyped
|
|
239
303
|
end
|
|
304
|
+
|
|
305
|
+
class ConcurrentRuby < Stores::Base
|
|
306
|
+
def initialize: () -> void
|
|
307
|
+
def read: (untyped key) -> untyped
|
|
308
|
+
def write: (untyped key, untyped value, ?expires_in: Numeric?) -> void
|
|
309
|
+
def delete: (untyped key) -> void
|
|
310
|
+
def clear: () -> void
|
|
311
|
+
def keys: () -> Array[untyped]
|
|
312
|
+
private
|
|
313
|
+
def expired?: ({ expires_at: Float?, value: untyped, cached_at: Float }) -> bool
|
|
314
|
+
end
|
|
240
315
|
end
|
|
241
316
|
|
|
242
317
|
module Rails
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: safe_memoize
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Chuck Smith
|
|
@@ -52,6 +52,7 @@ files:
|
|
|
52
52
|
- benchmarks/benchmark.rb
|
|
53
53
|
- codecov.yml
|
|
54
54
|
- lib/safe_memoize.rb
|
|
55
|
+
- lib/safe_memoize/adapters/concurrent_ruby.rb
|
|
55
56
|
- lib/safe_memoize/adapters/opentelemetry.rb
|
|
56
57
|
- lib/safe_memoize/adapters/statsd.rb
|
|
57
58
|
- lib/safe_memoize/cache_metrics_methods.rb
|
|
@@ -60,6 +61,8 @@ files:
|
|
|
60
61
|
- lib/safe_memoize/class_methods.rb
|
|
61
62
|
- lib/safe_memoize/configuration.rb
|
|
62
63
|
- lib/safe_memoize/custom_key_methods.rb
|
|
64
|
+
- lib/safe_memoize/extension.rb
|
|
65
|
+
- lib/safe_memoize/fiber_local_methods.rb
|
|
63
66
|
- lib/safe_memoize/hooks_methods.rb
|
|
64
67
|
- lib/safe_memoize/inspection_methods.rb
|
|
65
68
|
- lib/safe_memoize/instance_methods.rb
|
|
@@ -67,6 +70,7 @@ files:
|
|
|
67
70
|
- lib/safe_memoize/public_custom_key_methods.rb
|
|
68
71
|
- lib/safe_memoize/public_methods.rb
|
|
69
72
|
- lib/safe_memoize/public_metrics_methods.rb
|
|
73
|
+
- lib/safe_memoize/ractor_shared_methods.rb
|
|
70
74
|
- lib/safe_memoize/rails.rb
|
|
71
75
|
- lib/safe_memoize/rails/middleware.rb
|
|
72
76
|
- lib/safe_memoize/rails/request_scoped.rb
|