typed_cache 0.1.1 → 0.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
- checksums.yaml.gz.sig +0 -0
- data/README.md +139 -20
- data/examples.md +140 -50
- data/lib/typed_cache/backends/active_support.rb +50 -5
- data/lib/typed_cache/backends/memory.rb +14 -11
- data/lib/typed_cache/backends.rb +6 -8
- data/lib/typed_cache/cache_builder.rb +72 -19
- data/lib/typed_cache/cache_key.rb +11 -1
- data/lib/typed_cache/cache_ref.rb +20 -16
- data/lib/typed_cache/clock.rb +31 -14
- data/lib/typed_cache/decorator.rb +25 -0
- data/lib/typed_cache/decorators/instrumented.rb +92 -0
- data/lib/typed_cache/decorators.rb +7 -3
- data/lib/typed_cache/either.rb +22 -0
- data/lib/typed_cache/errors.rb +9 -1
- data/lib/typed_cache/instrumenter.rb +43 -0
- data/lib/typed_cache/instrumenters/active_support.rb +28 -0
- data/lib/typed_cache/instrumenters/mixins/namespaced_singleton.rb +55 -0
- data/lib/typed_cache/instrumenters/mixins.rb +8 -0
- data/lib/typed_cache/instrumenters/monitor.rb +27 -0
- data/lib/typed_cache/instrumenters/null.rb +26 -0
- data/lib/typed_cache/instrumenters.rb +39 -0
- data/lib/typed_cache/maybe.rb +18 -0
- data/lib/typed_cache/namespace.rb +33 -6
- data/lib/typed_cache/railtie.rb +15 -0
- data/lib/typed_cache/registry.rb +15 -0
- data/lib/typed_cache/snapshot.rb +18 -10
- data/lib/typed_cache/store.rb +50 -15
- data/lib/typed_cache/version.rb +1 -1
- data/lib/typed_cache.rb +34 -14
- data/rbi/typed_cache/backend.rbi +9 -0
- data/rbi/typed_cache/backends/active_support.rbi +13 -0
- data/rbi/typed_cache/backends/memory.rbi +13 -0
- data/rbi/typed_cache/backends.rbi +19 -0
- data/rbi/typed_cache/cache_builder.rbi +23 -0
- data/rbi/typed_cache/cache_key.rbi +16 -0
- data/rbi/typed_cache/cache_ref.rbi +56 -0
- data/rbi/typed_cache/decorator.rbi +67 -0
- data/rbi/typed_cache/decorators/instrumented.rbi +13 -0
- data/rbi/typed_cache/decorators.rbi +19 -0
- data/rbi/typed_cache/either.rbi +122 -0
- data/rbi/typed_cache/errors.rbi +20 -0
- data/rbi/typed_cache/instrumenter.rbi +45 -0
- data/rbi/typed_cache/instrumenters/mixins/namedspaced_singleton.rbi +33 -0
- data/rbi/typed_cache/instrumenters.rbi +19 -0
- data/rbi/typed_cache/maybe.rbi +108 -0
- data/rbi/typed_cache/namespace.rbi +30 -0
- data/rbi/typed_cache/snapshot.rbi +54 -0
- data/rbi/typed_cache/store.rbi +71 -0
- data/rbi/typed_cache/version.rbi +5 -0
- data/rbi/typed_cache.rbi +49 -0
- data/sig/generated/typed_cache/backends/active_support.rbs +14 -2
- data/sig/generated/typed_cache/backends/memory.rbs +2 -2
- data/sig/generated/typed_cache/backends.rbs +2 -0
- data/sig/generated/typed_cache/cache_builder.rbs +13 -2
- data/sig/generated/typed_cache/cache_key.rbs +5 -0
- data/sig/generated/typed_cache/cache_ref.rbs +4 -4
- data/sig/generated/typed_cache/clock.rbs +19 -9
- data/sig/generated/typed_cache/decorator.rbs +12 -0
- data/sig/generated/typed_cache/decorators/instrumented.rbs +35 -0
- data/sig/generated/typed_cache/decorators.rbs +2 -0
- data/sig/generated/typed_cache/either.rbs +24 -0
- data/sig/generated/typed_cache/errors.rbs +2 -0
- data/sig/generated/typed_cache/instrumenter.rbs +31 -0
- data/sig/generated/typed_cache/instrumenters/active_support.rbs +20 -0
- data/sig/generated/typed_cache/instrumenters/mixins/namespaced_singleton.rbs +36 -0
- data/sig/generated/typed_cache/instrumenters/mixins.rbs +8 -0
- data/sig/generated/typed_cache/instrumenters/monitor.rbs +19 -0
- data/sig/generated/typed_cache/instrumenters/null.rbs +21 -0
- data/sig/generated/typed_cache/instrumenters.rbs +26 -0
- data/sig/generated/typed_cache/maybe.rbs +20 -0
- data/sig/generated/typed_cache/namespace.rbs +24 -3
- data/sig/generated/typed_cache/railtie.rbs +6 -0
- data/sig/generated/typed_cache/registry.rbs +8 -0
- data/sig/generated/typed_cache/snapshot.rbs +12 -6
- data/sig/generated/typed_cache/store/instrumented.rbs +2 -6
- data/sig/generated/typed_cache/store.rbs +26 -8
- data/sig/generated/typed_cache.rbs +8 -6
- data/typed_cache.gemspec +5 -4
- data.tar.gz.sig +0 -0
- metadata +48 -27
- metadata.gz.sig +0 -0
- data/lib/typed_cache/instrumentation.rb +0 -112
- data/lib/typed_cache/store/instrumented.rb +0 -83
- data/sig/generated/typed_cache/instrumentation.rbs +0 -30
- data/sig/handwritten/gems/zeitwerk/2.7/zeitwerk.rbs +0 -9
data/rbi/typed_cache.rbi
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# typed: strict
|
2
|
+
|
3
|
+
module TypedCache
|
4
|
+
module Private
|
5
|
+
class Configuration < BasicObject
|
6
|
+
class Instrumentation < BasicObject
|
7
|
+
sig { returns(T::Boolean) }
|
8
|
+
attr_accessor :enabled
|
9
|
+
|
10
|
+
sig { returns(String) }
|
11
|
+
attr_accessor :namespace
|
12
|
+
|
13
|
+
sig { returns(Symbol) }
|
14
|
+
attr_accessor :instrumenter
|
15
|
+
end
|
16
|
+
|
17
|
+
sig { returns(String) }
|
18
|
+
attr_accessor :namespace
|
19
|
+
|
20
|
+
sig { returns(String) }
|
21
|
+
attr_accessor :cache_delimiter
|
22
|
+
|
23
|
+
sig { returns(::TypedCache::Private::Configuration::Instrumentation) }
|
24
|
+
def instrumentation; end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
class << self
|
29
|
+
sig { params(block: T.proc.params(config: ::TypedCache::Private::Configuration).void).void }
|
30
|
+
def configure(&block); end
|
31
|
+
|
32
|
+
sig { returns(::TypedCache::Private::Configuration) }
|
33
|
+
def config; end
|
34
|
+
|
35
|
+
sig { returns(::TypedCache::CacheBuilder) }
|
36
|
+
def builder; end
|
37
|
+
|
38
|
+
sig { returns(T.class_of(::TypedCache::Backends)) }
|
39
|
+
def backends; end
|
40
|
+
|
41
|
+
sig { returns(T.class_of(::TypedCache::Decorators)) }
|
42
|
+
def decorators; end
|
43
|
+
|
44
|
+
sig { returns(T.class_of(::TypedCache::Instrumenters)) }
|
45
|
+
def instrumenters; end
|
46
|
+
end
|
47
|
+
|
48
|
+
private_constant :Backends, :Decorators, :Instrumenters
|
49
|
+
end
|
@@ -18,16 +18,28 @@ module TypedCache
|
|
18
18
|
|
19
19
|
# @rbs override
|
20
20
|
# : (cache_key) -> either[Error, Snapshot[V]]
|
21
|
-
def
|
21
|
+
def read: ...
|
22
22
|
|
23
23
|
# @rbs override
|
24
24
|
# : (cache_key, V) -> either[Error, Snapshot[V]]
|
25
|
-
def
|
25
|
+
def write: ...
|
26
|
+
|
27
|
+
# @rbs override
|
28
|
+
# : (Hash[cache_key, V]) -> either[Error, Array[Snapshot[V]]]
|
29
|
+
def write_all: ...
|
26
30
|
|
27
31
|
# @rbs override
|
28
32
|
# : (cache_key) -> either[Error, Snapshot[V]]
|
29
33
|
def delete: ...
|
30
34
|
|
35
|
+
# @rbs override
|
36
|
+
# : (Array[cache_key]) -> either[Error, Array[Snapshot[V]]]
|
37
|
+
def read_all: ...
|
38
|
+
|
39
|
+
# @rbs override
|
40
|
+
# : (Array[cache_key]) { (CacheKey) -> V? } -> either[Error, Array[Snapshot[V]]]
|
41
|
+
def fetch_all: ...
|
42
|
+
|
31
43
|
# @rbs override
|
32
44
|
# : (cache_key) -> bool
|
33
45
|
def key?: ...
|
@@ -55,11 +55,11 @@ module TypedCache
|
|
55
55
|
|
56
56
|
# @rbs override
|
57
57
|
# : (cache_key) -> either[Error, Snapshot[V]]
|
58
|
-
def
|
58
|
+
def read: ...
|
59
59
|
|
60
60
|
# @rbs override
|
61
61
|
# : (cache_key, V) -> either[Error, Snapshot[V]]
|
62
|
-
def
|
62
|
+
def write: ...
|
63
63
|
|
64
64
|
# @rbs override
|
65
65
|
# : (cache_key) -> either[Error, Snapshot[V]]
|
@@ -4,6 +4,14 @@ module TypedCache
|
|
4
4
|
class CacheBuilder
|
5
5
|
type config = TypedCache::typed_cache_config
|
6
6
|
|
7
|
+
type instrumenter_source = :default | :dry | :rails | Instrumenter
|
8
|
+
|
9
|
+
class BackendConfig < Dry::Struct
|
10
|
+
end
|
11
|
+
|
12
|
+
class DecoratorConfig < Dry::Struct
|
13
|
+
end
|
14
|
+
|
7
15
|
# @rbs (config, Registry[backend[untyped]], Registry[decorator[untyped]]) -> void
|
8
16
|
def initialize: (config, Registry[backend[untyped]], Registry[decorator[untyped]]) -> void
|
9
17
|
|
@@ -20,8 +28,9 @@ module TypedCache
|
|
20
28
|
# @rbs (Symbol) -> self
|
21
29
|
def with_decorator: (Symbol) -> self
|
22
30
|
|
23
|
-
#
|
24
|
-
|
31
|
+
# Adds instrumentation using the specified strategy.
|
32
|
+
# @rbs (instrumenter_source) -> either[Error, self]
|
33
|
+
def with_instrumentation: (instrumenter_source) -> either[Error, self]
|
25
34
|
|
26
35
|
private
|
27
36
|
|
@@ -33,5 +42,7 @@ module TypedCache
|
|
33
42
|
|
34
43
|
# @rbs (Store[V]) -> either[Error, Store[V]]
|
35
44
|
def apply_decorators: (Store[V]) -> either[Error, Store[V]]
|
45
|
+
|
46
|
+
def apply_instrumentation: (untyped store) -> untyped
|
36
47
|
end
|
37
48
|
end
|
@@ -16,11 +16,11 @@ module TypedCache
|
|
16
16
|
|
17
17
|
# Gets a value from the cache as a snapshot
|
18
18
|
# : -> either[Error, Snapshot[V]]
|
19
|
-
def
|
19
|
+
def read: () -> either[Error, Snapshot[V]]
|
20
20
|
|
21
21
|
# Sets a value in the cache and returns it as an updated snapshot
|
22
22
|
# : (V) -> either[Error, Snapshot[V]]
|
23
|
-
def
|
23
|
+
def write: (V) -> either[Error, Snapshot[V]]
|
24
24
|
|
25
25
|
# Deletes the value from the cache and returns the deleted value as a snapshot
|
26
26
|
# : -> either[Error, Snapshot[V]]
|
@@ -77,8 +77,8 @@ module TypedCache
|
|
77
77
|
def scope: [R] (String) -> CacheRef[R]
|
78
78
|
|
79
79
|
# Pattern matching support for Either[Error, Snapshot[V]] results
|
80
|
-
# : [R] (
|
81
|
-
def fold: (
|
80
|
+
# : [R] (^(Error) -> R, ^(Snapshot[V]) -> R) -> R
|
81
|
+
def fold: [R] (^(Error) -> R, ^(Snapshot[V]) -> R) -> R
|
82
82
|
|
83
83
|
# Convenience method to work with the snapshot directly
|
84
84
|
# : [R] () { (Snapshot[V]) -> R } -> either[Error, R]
|
@@ -1,15 +1,25 @@
|
|
1
1
|
# Generated from lib/typed_cache/clock.rb with RBS::Inline
|
2
2
|
|
3
3
|
module TypedCache
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
4
|
+
module Clock
|
5
|
+
# @rbs generic R
|
6
|
+
class Measured[R] < Dry::Struct
|
7
|
+
def start: () -> Float
|
8
|
+
|
9
|
+
def end: () -> Float
|
10
|
+
|
11
|
+
def result: () -> [ R ]
|
12
|
+
|
13
|
+
def initialize: (start: Float, end: Float, result: [ R ]) -> void
|
14
|
+
|
15
|
+
# : -> Float
|
16
|
+
def duration: () -> Float
|
17
|
+
end
|
18
|
+
|
19
|
+
# @rbs [R]() { () -> R } -> Measured[R]
|
20
|
+
def self.measure: [R] () { () -> R } -> Measured[R]
|
21
|
+
|
12
22
|
# @rbs () -> Time
|
13
|
-
def self.
|
23
|
+
def self.now: () -> Time
|
14
24
|
end
|
15
25
|
end
|
@@ -5,10 +5,22 @@ module TypedCache
|
|
5
5
|
# Store but must accept another Store instance in its constructor.
|
6
6
|
# @rbs generic V
|
7
7
|
module Decorator[V]
|
8
|
+
extend Forwardable
|
9
|
+
|
8
10
|
include Store[V]
|
9
11
|
|
10
12
|
include Store::_Store[V]
|
11
13
|
|
12
14
|
include Store::_Decorator[V]
|
15
|
+
|
16
|
+
def store: () -> Store[V]
|
17
|
+
|
18
|
+
# @rbs override
|
19
|
+
# : (cache_key) -> either[Error, CacheRef[V]]
|
20
|
+
def ref: ...
|
21
|
+
|
22
|
+
# @rbs override
|
23
|
+
# : (self) -> void
|
24
|
+
def initialize_copy: ...
|
13
25
|
end
|
14
26
|
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# Generated from lib/typed_cache/decorators/instrumented.rb with RBS::Inline
|
2
|
+
|
3
|
+
module TypedCache
|
4
|
+
# Decorator that adds instrumentation to any Store implementation
|
5
|
+
# This decorator can wrap any store to add ActiveSupport::Notifications
|
6
|
+
# @rbs generic V
|
7
|
+
class Decorators::Instrumented[V]
|
8
|
+
include Decorator[V]
|
9
|
+
|
10
|
+
extend Forwardable
|
11
|
+
|
12
|
+
attr_reader store: TypedCache::Store[V]
|
13
|
+
|
14
|
+
attr_reader instrumenter: Instrumenter
|
15
|
+
|
16
|
+
# @rbs (Symbol, ?operation: String) ?{ (*untyped, **untyped) -> String } -> void
|
17
|
+
private def self.instrument: (Symbol, ?operation: String) ?{ (*untyped, **untyped) -> String } -> void
|
18
|
+
|
19
|
+
# : (TypedCache::Store[V], instrumenter: Instrumenter) -> void
|
20
|
+
def initialize: (TypedCache::Store[V], instrumenter: Instrumenter) -> void
|
21
|
+
|
22
|
+
# @rbs override
|
23
|
+
# : (self) -> self
|
24
|
+
def initialize_copy: ...
|
25
|
+
|
26
|
+
# @rbs override
|
27
|
+
# : -> String
|
28
|
+
def store_type: ...
|
29
|
+
|
30
|
+
# Additional methods that might exist on the wrapped store
|
31
|
+
def respond_to_missing?: (untyped method_name, ?untyped include_private) -> untyped
|
32
|
+
|
33
|
+
def method_missing: (untyped method_name, *untyped args) ?{ (?) -> untyped } -> untyped
|
34
|
+
end
|
35
|
+
end
|
@@ -13,12 +13,14 @@ module TypedCache
|
|
13
13
|
# .with_decorator(:my_decorator)
|
14
14
|
# .build.value
|
15
15
|
module Decorators
|
16
|
+
# @api private
|
16
17
|
# Default decorator set – starts with instrumentation only, but this registry
|
17
18
|
# lets end-users register their own via `Decorators.register`.
|
18
19
|
REGISTRY: untyped
|
19
20
|
|
20
21
|
extend Forwardable
|
21
22
|
|
23
|
+
# @api private
|
22
24
|
# @rbs () -> Registry[Store[untyped]]
|
23
25
|
def self.registry: () -> Registry[Store[untyped]]
|
24
26
|
end
|
@@ -21,6 +21,10 @@ module TypedCache
|
|
21
21
|
|
22
22
|
def right?: () -> bool
|
23
23
|
|
24
|
+
def right_or_else: (^(E) -> void) -> R
|
25
|
+
|
26
|
+
def right_or_raise!: () -> R
|
27
|
+
|
24
28
|
def map: [T] () { (R) -> T } -> either[E, T]
|
25
29
|
|
26
30
|
def bind: [E2, R2] () { (R) -> either[E2, R2] } -> either[E | E2, R2]
|
@@ -36,6 +40,8 @@ module TypedCache
|
|
36
40
|
|
37
41
|
attr_reader error: E
|
38
42
|
|
43
|
+
alias value error
|
44
|
+
|
39
45
|
# : (E) -> void
|
40
46
|
def initialize: (E) -> void
|
41
47
|
|
@@ -47,6 +53,14 @@ module TypedCache
|
|
47
53
|
# : -> false
|
48
54
|
def right?: ...
|
49
55
|
|
56
|
+
# @rbs override
|
57
|
+
# : (^(E) -> void) -> bot
|
58
|
+
def right_or_else: ...
|
59
|
+
|
60
|
+
# @rbs override
|
61
|
+
# : -> bot
|
62
|
+
def right_or_raise!: ...
|
63
|
+
|
50
64
|
# @rbs override
|
51
65
|
# : [T] () { (R) -> T } -> either[E, T]
|
52
66
|
def map: ...
|
@@ -73,6 +87,8 @@ module TypedCache
|
|
73
87
|
|
74
88
|
attr_reader value: R
|
75
89
|
|
90
|
+
alias result value
|
91
|
+
|
76
92
|
# : (R) -> void
|
77
93
|
def initialize: (R) -> void
|
78
94
|
|
@@ -84,6 +100,14 @@ module TypedCache
|
|
84
100
|
# : -> true
|
85
101
|
def right?: ...
|
86
102
|
|
103
|
+
# @rbs override
|
104
|
+
# : (^(E) -> void) -> R
|
105
|
+
def right_or_else: ...
|
106
|
+
|
107
|
+
# @rbs override
|
108
|
+
# : -> R
|
109
|
+
def right_or_raise!: ...
|
110
|
+
|
87
111
|
# @rbs override
|
88
112
|
# : [T] () { (R) -> T } -> either[E, T]
|
89
113
|
def map: ...
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# Generated from lib/typed_cache/instrumenter.rb with RBS::Inline
|
2
|
+
|
3
|
+
module TypedCache
|
4
|
+
# Instrumenter for cache operations
|
5
|
+
module Instrumenter
|
6
|
+
type event = Dry::Events::Event | ActiveSupport::Notifications::Event
|
7
|
+
|
8
|
+
# @rbs [R](String, String, **untyped) { -> R } -> R
|
9
|
+
def instrument: [R] (String, String, **untyped) { () -> R } -> R
|
10
|
+
|
11
|
+
# @rbs (String, **untyped) { (event) -> void } -> void
|
12
|
+
def subscribe: (String, **untyped) { (event) -> void } -> void
|
13
|
+
|
14
|
+
# : -> String
|
15
|
+
def namespace: () -> String
|
16
|
+
|
17
|
+
# @rbs () -> bool
|
18
|
+
def enabled?: () -> bool
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
# @rbs (String, String, **untyped) -> Hash[Symbol, untyped]
|
23
|
+
def build_payload: (String, String, **untyped) -> Hash[Symbol, untyped]
|
24
|
+
|
25
|
+
# @rbs (String) -> String
|
26
|
+
def event_name: (String) -> String
|
27
|
+
|
28
|
+
# @rbs () -> TypedCache::_TypedCacheInstrumentationConfig
|
29
|
+
def config: () -> TypedCache::_TypedCacheInstrumentationConfig
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# Generated from lib/typed_cache/instrumenters/active_support.rb with RBS::Inline
|
2
|
+
|
3
|
+
module TypedCache
|
4
|
+
module Instrumenters
|
5
|
+
# Instrumenter for ActiveSupport::Notifications
|
6
|
+
class ActiveSupport
|
7
|
+
include Instrumenter
|
8
|
+
|
9
|
+
include Mixins::NamespacedSingleton
|
10
|
+
|
11
|
+
# @rbs override
|
12
|
+
# : [R] (String, String, Hash[Symbol, untyped]) { -> R } -> R
|
13
|
+
def instrument: ...
|
14
|
+
|
15
|
+
# @rbs override
|
16
|
+
# @rbs (String, **top) { (event) -> void } -> void
|
17
|
+
def subscribe: ...
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# Generated from lib/typed_cache/instrumenters/mixins/namespaced_singleton.rb with RBS::Inline
|
2
|
+
|
3
|
+
module TypedCache
|
4
|
+
module Instrumenters
|
5
|
+
module Mixins
|
6
|
+
module NamespacedSingleton
|
7
|
+
# @rbs () -> Array[Class[Instrumenter & NamespacedSingleton]]
|
8
|
+
def self.all: () -> Array[Class[Instrumenter & NamespacedSingleton]]
|
9
|
+
|
10
|
+
# @rbs (Class[Instrumenter & NamespacedSingleton]) -> void
|
11
|
+
def self.included: (Class[Instrumenter & NamespacedSingleton]) -> void
|
12
|
+
|
13
|
+
# @rbs override
|
14
|
+
# @rbs () -> String
|
15
|
+
def namespace: ...
|
16
|
+
|
17
|
+
# @rbs (String | Namespace) -> void
|
18
|
+
def initialize: (String | Namespace) -> void
|
19
|
+
|
20
|
+
module ClassMethods
|
21
|
+
# @rbs (String | Namespace) -> class
|
22
|
+
def new: (String | Namespace) -> class
|
23
|
+
|
24
|
+
# @rbs (String) -> maybe[class]
|
25
|
+
def get: (String) -> maybe[class]
|
26
|
+
|
27
|
+
# @rbs () -> void
|
28
|
+
def clear_namespace_cache: () -> void
|
29
|
+
|
30
|
+
# @rbs () -> Concurrent::Map[String, Class[Instrumenter & NamespacedSingleton]]
|
31
|
+
def namespace_cache: () -> Concurrent::Map[String, Class[Instrumenter & NamespacedSingleton]]
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# Generated from lib/typed_cache/instrumenters/monitor.rb with RBS::Inline
|
2
|
+
|
3
|
+
module TypedCache
|
4
|
+
module Instrumenters
|
5
|
+
class Monitor
|
6
|
+
include Instrumenter
|
7
|
+
|
8
|
+
include Mixins::NamespacedSingleton
|
9
|
+
|
10
|
+
# @rbs override
|
11
|
+
# : [R] (String, String, **untyped) { -> R } -> R
|
12
|
+
def instrument: ...
|
13
|
+
|
14
|
+
# @rbs override
|
15
|
+
# @rbs (String, **top) { (event) -> void } -> void
|
16
|
+
def subscribe: ...
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# Generated from lib/typed_cache/instrumenters/null.rb with RBS::Inline
|
2
|
+
|
3
|
+
module TypedCache
|
4
|
+
module Instrumenters
|
5
|
+
# A no-op implementation used when instrumentation is disabled.
|
6
|
+
# It fulfils the Instrumenter contract but simply yields.
|
7
|
+
class Null
|
8
|
+
include Instrumenter
|
9
|
+
|
10
|
+
include Mixins::NamespacedSingleton
|
11
|
+
|
12
|
+
# @rbs override
|
13
|
+
# [R] (String, String, **untyped) { -> R } -> R
|
14
|
+
def instrument: ...
|
15
|
+
|
16
|
+
# @rbs override
|
17
|
+
# @rbs (String, **top) { (event) -> void } -> void
|
18
|
+
def subscribe: ...
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# Generated from lib/typed_cache/instrumenters.rb with RBS::Inline
|
2
|
+
|
3
|
+
module TypedCache
|
4
|
+
module Instrumenters
|
5
|
+
# @api private
|
6
|
+
# Registry mapping symbols to instrumenter classes. We can't reuse the generic
|
7
|
+
# Registry class directly because many instrumenters mix in `Singleton`,
|
8
|
+
# making `.new` inaccessible. Instead we implement a thin facade that
|
9
|
+
# returns either the singleton instance (preferred) or a fresh instance.
|
10
|
+
REGISTRY: Registry[Symbol, Class[Instrumenter]]
|
11
|
+
|
12
|
+
extend Forwardable
|
13
|
+
|
14
|
+
# @api private
|
15
|
+
# @rbs () -> Registry[Symbol, Class[Instrumenter]]
|
16
|
+
def self.registry: () -> Registry[Symbol, Class[Instrumenter]]
|
17
|
+
|
18
|
+
def register: (Symbol, Class[Instrumenter]) -> void
|
19
|
+
|
20
|
+
def resolve: (Symbol, **untyped) -> either[Error, Instrumenter]
|
21
|
+
|
22
|
+
def available: () -> Array[Symbol]
|
23
|
+
|
24
|
+
def registered?: (Symbol) -> Boolean
|
25
|
+
end
|
26
|
+
end
|
@@ -27,6 +27,10 @@ module TypedCache
|
|
27
27
|
|
28
28
|
def bind: [T] () { (V) -> maybe[T] } -> maybe[T]
|
29
29
|
|
30
|
+
def value_or: [T] (T) -> T
|
31
|
+
|
32
|
+
def value_or_raise!: () -> V
|
33
|
+
|
30
34
|
alias flat_map bind
|
31
35
|
end
|
32
36
|
|
@@ -55,6 +59,14 @@ module TypedCache
|
|
55
59
|
# : [T] () { (V) -> maybe[T] } -> maybe[T]
|
56
60
|
def bind: ...
|
57
61
|
|
62
|
+
# @rbs override
|
63
|
+
# : [T] (T) -> T
|
64
|
+
def value_or: ...
|
65
|
+
|
66
|
+
# @rbs override
|
67
|
+
# : -> V
|
68
|
+
def value_or_raise!: ...
|
69
|
+
|
58
70
|
alias flat_map bind
|
59
71
|
|
60
72
|
# : (Array[top]) -> ({ value: V })
|
@@ -81,5 +93,13 @@ module TypedCache
|
|
81
93
|
def bind: ...
|
82
94
|
|
83
95
|
alias flat_map bind
|
96
|
+
|
97
|
+
# @rbs override
|
98
|
+
# : [T] (T) -> T
|
99
|
+
def value_or: ...
|
100
|
+
|
101
|
+
# @rbs override
|
102
|
+
# : -> V
|
103
|
+
def value_or_raise!: ...
|
84
104
|
end
|
85
105
|
end
|
@@ -19,15 +19,16 @@ module TypedCache
|
|
19
19
|
# Returns a new Namespace instance rooted at the given namespace string.
|
20
20
|
#
|
21
21
|
# @param namespace [String] the root namespace
|
22
|
+
# @param namespaces [Array<String>] additional namespaces to join
|
22
23
|
# @return [Namespace] a new Namespace instance at the given root
|
23
24
|
#
|
24
25
|
# Example:
|
25
|
-
# TypedCache::Namespace.at("users") # => #<TypedCache::Namespace namespace=users>
|
26
|
+
# TypedCache::Namespace.at("users", "sessions") # => #<TypedCache::Namespace namespace=users:sessions>
|
26
27
|
#
|
27
28
|
# The returned Namespace can be further nested or used to generate cache keys.
|
28
29
|
#
|
29
|
-
# @rbs (String) -> Namespace
|
30
|
-
def self.at: (String) -> Namespace
|
30
|
+
# @rbs (String, *String) -> Namespace
|
31
|
+
def self.at: (String, *String) -> Namespace
|
31
32
|
|
32
33
|
# Returns the root Namespace instance (with an empty namespace).
|
33
34
|
#
|
@@ -69,6 +70,21 @@ module TypedCache
|
|
69
70
|
# @rbs (String) ?{ (Namespace, String) -> CacheKey } -> Namespace
|
70
71
|
def nested: (String) ?{ (Namespace, String) -> CacheKey } -> Namespace
|
71
72
|
|
73
|
+
# Creates a new namespace by joining the current namespace with the given namespaces.
|
74
|
+
#
|
75
|
+
# @param namespaces [Array<String>] the namespaces to join
|
76
|
+
# @param key_factory [Proc, nil] optional custom key factory for the joined namespace
|
77
|
+
# @return [Namespace] a new Namespace instance with the combined namespace
|
78
|
+
#
|
79
|
+
# Example:
|
80
|
+
# ns = Namespace.at("users")
|
81
|
+
# ns.join("sessions", "admin") # => #<TypedCache::Namespace namespace=users:sessions:admin>
|
82
|
+
#
|
83
|
+
# If no key_factory is provided, the parent's key factory is inherited.
|
84
|
+
#
|
85
|
+
# @rbs (*String) ?{ (Namespace, String) -> CacheKey } -> Namespace
|
86
|
+
def join: (*String) ?{ (Namespace, String) -> CacheKey } -> Namespace
|
87
|
+
|
72
88
|
# Returns the parent namespace by removing the last namespace segment.
|
73
89
|
#
|
74
90
|
# @return [Namespace] the parent namespace, or self if already at root
|
@@ -126,5 +142,10 @@ module TypedCache
|
|
126
142
|
def ==: (Object) -> bool
|
127
143
|
|
128
144
|
alias eql? ==
|
145
|
+
|
146
|
+
private
|
147
|
+
|
148
|
+
# @rbs (String) -> String
|
149
|
+
def delimiter: (String) -> String
|
129
150
|
end
|
130
151
|
end
|
@@ -7,6 +7,12 @@ module TypedCache
|
|
7
7
|
# @rbs (String, Hash[Symbol, Class[T]]) -> void
|
8
8
|
def initialize: (String, Hash[Symbol, Class[T]]) -> void
|
9
9
|
|
10
|
+
# @rbs (Registry[T]) -> Registry[T]
|
11
|
+
def initialize_copy: (Registry[T]) -> Registry[T]
|
12
|
+
|
13
|
+
# @rbs () -> void
|
14
|
+
def clear: () -> void
|
15
|
+
|
10
16
|
# @rbs (Symbol, *untyped, **untyped) -> either[Error, T]
|
11
17
|
def resolve: (Symbol, *untyped, **untyped) -> either[Error, T]
|
12
18
|
|
@@ -21,5 +27,7 @@ module TypedCache
|
|
21
27
|
|
22
28
|
# @rbs (Symbol) -> bool
|
23
29
|
def registered?: (Symbol) -> bool
|
30
|
+
|
31
|
+
attr_reader registry: Hash[Symbol, Class[T]]
|
24
32
|
end
|
25
33
|
end
|