typed_cache 0.3.1 → 0.4.0.pre.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.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/lib/typed_cache/backend.rb +80 -2
  4. data/lib/typed_cache/backends/active_support.rb +24 -98
  5. data/lib/typed_cache/backends/memory.rb +22 -73
  6. data/lib/typed_cache/backends.rb +2 -2
  7. data/lib/typed_cache/cache_builder.rb +131 -46
  8. data/lib/typed_cache/cache_key.rb +1 -1
  9. data/lib/typed_cache/cache_ref.rb +24 -55
  10. data/lib/typed_cache/decorator.rb +22 -12
  11. data/lib/typed_cache/decorators/instrumented.rb +12 -19
  12. data/lib/typed_cache/decorators.rb +7 -1
  13. data/lib/typed_cache/either.rb +28 -0
  14. data/lib/typed_cache/instrumenters.rb +6 -2
  15. data/lib/typed_cache/maybe.rb +28 -0
  16. data/lib/typed_cache/namespace.rb +1 -3
  17. data/lib/typed_cache/snapshot.rb +6 -0
  18. data/lib/typed_cache/store.rb +130 -78
  19. data/lib/typed_cache/version.rb +1 -1
  20. data/lib/typed_cache.rb +5 -2
  21. data/rbi/typed_cache/backend.rbi +44 -2
  22. data/rbi/typed_cache/backends/active_support.rbi +1 -1
  23. data/rbi/typed_cache/backends/memory.rbi +1 -1
  24. data/rbi/typed_cache/cache_builder.rbi +29 -10
  25. data/rbi/typed_cache/cache_key.rbi +14 -0
  26. data/rbi/typed_cache/cache_ref.rbi +6 -15
  27. data/rbi/typed_cache/decorator.rbi +23 -37
  28. data/rbi/typed_cache/decorators/instrumented.rbi +1 -1
  29. data/rbi/typed_cache/either.rbi +24 -0
  30. data/rbi/typed_cache/maybe.rbi +24 -0
  31. data/rbi/typed_cache/namespace.rbi +14 -0
  32. data/rbi/typed_cache/snapshot.rbi +6 -0
  33. data/rbi/typed_cache/store.rbi +26 -24
  34. data/rbi/typed_cache.rbi +1 -1
  35. data/sig/generated/typed_cache/backend.rbs +68 -2
  36. data/sig/generated/typed_cache/backends/active_support.rbs +13 -21
  37. data/sig/generated/typed_cache/backends/memory.rbs +10 -30
  38. data/sig/generated/typed_cache/backends.rbs +2 -2
  39. data/sig/generated/typed_cache/cache_builder.rbs +57 -16
  40. data/sig/generated/typed_cache/cache_ref.rbs +16 -37
  41. data/sig/generated/typed_cache/decorator.rbs +18 -6
  42. data/sig/generated/typed_cache/decorators/instrumented.rbs +3 -7
  43. data/sig/generated/typed_cache/decorators.rbs +9 -1
  44. data/sig/generated/typed_cache/either.rbs +24 -0
  45. data/sig/generated/typed_cache/instrumenters.rbs +4 -3
  46. data/sig/generated/typed_cache/maybe.rbs +24 -0
  47. data/sig/generated/typed_cache/namespace.rbs +0 -2
  48. data/sig/generated/typed_cache/snapshot.rbs +6 -0
  49. data/sig/generated/typed_cache/store.rbs +49 -42
  50. data/sig/generated/typed_cache.rbs +6 -2
  51. data.tar.gz.sig +0 -0
  52. metadata +3 -3
  53. metadata.gz.sig +0 -0
@@ -77,6 +77,18 @@ module TypedCache
77
77
 
78
78
  sig { override.returns(V) }
79
79
  def value_or_raise!; end
80
+
81
+ sig { returns(String) }
82
+ def to_s; end
83
+
84
+ sig { returns(String) }
85
+ def inspect; end
86
+
87
+ sig { params(other: Object).returns(T::Boolean) }
88
+ def ==(other); end
89
+
90
+ sig { returns(Integer) }
91
+ def hash; end
80
92
  end
81
93
 
82
94
  class Nothing
@@ -104,5 +116,17 @@ module TypedCache
104
116
 
105
117
  sig { override.returns(T.noreturn) }
106
118
  def value_or_raise!; end
119
+
120
+ sig { returns(String) }
121
+ def to_s; end
122
+
123
+ sig { returns(String) }
124
+ def inspect; end
125
+
126
+ sig { params(other: Object).returns(T::Boolean) }
127
+ def ==(other); end
128
+
129
+ sig { returns(Integer) }
130
+ def hash; end
107
131
  end
108
132
  end
@@ -26,5 +26,19 @@ module TypedCache
26
26
 
27
27
  sig { returns(String) }
28
28
  def to_s; end
29
+
30
+ sig { returns(String) }
31
+ def inspect; end
32
+
33
+ sig { returns(Integer) }
34
+ def hash; end
35
+
36
+ sig { params(other: Object).returns(T::Boolean) }
37
+ def ==(other); end
38
+
39
+ private
40
+
41
+ sig { returns(String) }
42
+ def delimiter; end
29
43
  end
30
44
  end
@@ -40,6 +40,12 @@ module TypedCache
40
40
 
41
41
  alias flat_map bind
42
42
 
43
+ sig { returns(String) }
44
+ def to_s; end
45
+
46
+ sig { returns(String) }
47
+ def inspect; end
48
+
43
49
  class << self
44
50
  sig { type_parameters(:T).params(key: ::TypedCache::CacheKey, value: T.type_parameter(:T)).returns(::TypedCache::Snapshot[T.type_parameter(:T)]) }
45
51
  def cached(key, value); end
@@ -12,10 +12,16 @@ module TypedCache
12
12
  Key = T.type_alias { T.any(String, ::TypedCache::CacheKey) }
13
13
  private_constant :Error, :Key
14
14
 
15
- sig { params(key: Key, kwargs: T::Hash[Symbol, T.untyped]).returns(::TypedCache::Either[Error, CachedType]) }
15
+ sig { returns(::TypedCache::Backend[CachedType]) }
16
+ def backend; end
17
+
18
+ sig { params(key: Key, kwargs: T::Hash[Symbol, T.untyped]).returns(::TypedCache::Either[Error, ::TypedCache::Snapshot[::TypedCache::Maybe[CachedType]]]) }
16
19
  def read(key, **kwargs); end
17
20
 
18
- sig { params(keys: T::Array[Key], kwargs: T::Hash[Symbol, T.untyped]).returns(::TypedCache::Either[Error, T::Array[::TypedCache::Snapshot[CachedType]]]) }
21
+ sig do
22
+ type_parameters(:K)
23
+ .params(keys: T::Array[T.all(Key, T.type_parameter(:K))], kwargs: T::Hash[Symbol, T.untyped]).returns(::TypedCache::Either[Error, T::Hash[T.all(Key, T.type_parameter(:K)), ::TypedCache::Snapshot[CachedType]]])
24
+ end
19
25
  def read_all(keys, **kwargs); end
20
26
 
21
27
  sig { params(key: Key, value: CachedType, kwargs: T::Hash[Symbol, T.untyped]).returns(::TypedCache::Either[Error, ::TypedCache::Snapshot[CachedType]]) }
@@ -24,7 +30,7 @@ module TypedCache
24
30
  sig { params(values: T::Hash[Key, CachedType], kwargs: T::Hash[Symbol, T.untyped]).returns(::TypedCache::Either[Error, T::Array[::TypedCache::Snapshot[CachedType]]]) }
25
31
  def write_all(values, **kwargs); end
26
32
 
27
- sig { params(key: Key).returns(::TypedCache::Either[Error, ::TypedCache::Snapshot[CachedType]]) }
33
+ sig { params(key: Key).returns(::TypedCache::Either[Error, ::TypedCache::Maybe[CachedType]]) }
28
34
  def delete(key); end
29
35
 
30
36
  sig { params(key: Key).returns(::TypedCache::CacheRef[CachedType]) }
@@ -36,10 +42,16 @@ module TypedCache
36
42
  sig { params(key: Key).returns(T::Boolean) }
37
43
  def key?(key); end
38
44
 
39
- sig { params(key: Key, kwargs: T::Hash[Symbol, T.untyped], block: T.proc.returns(T.nilable(CachedType))).returns(::TypedCache::Either[Error, ::TypedCache::Snapshot[::TypedCache::Maybe[CachedType]]]) }
45
+ sig do
46
+ type_parameters(:K)
47
+ .params(key: T.all(Key, T.type_parameter(:K)), kwargs: T::Hash[Symbol, T.untyped], block: T.proc.params(key: T.all(Key, T.type_parameter(:K))).returns(T.nilable(CachedType))).returns(::TypedCache::Either[Error, ::TypedCache::Snapshot[::TypedCache::Maybe[CachedType]]])
48
+ end
40
49
  def fetch(key, **kwargs, &block); end
41
50
 
42
- sig { params(keys: T::Array[Key], kwargs: T::Hash[Symbol, T.untyped], block: T.proc.params(key: ::TypedCache::CacheKey).returns(T.nilable(CachedType))).returns(::TypedCache::Either[Error, T::Array[::TypedCache::Snapshot[CachedType]]]) }
51
+ sig do
52
+ type_parameters(:K)
53
+ .params(keys: T::Array[T.all(Key, T.type_parameter(:K))], kwargs: T::Hash[Symbol, T.untyped], block: T.proc.params(key: T.all(Key, T.type_parameter(:K))).returns(T.nilable(CachedType))).returns(::TypedCache::Either[Error, T::Hash[T.all(Key, T.type_parameter(:K)), ::TypedCache::Snapshot[CachedType]]])
54
+ end
43
55
  def fetch_all(keys, **kwargs, &block); end
44
56
 
45
57
  sig { returns(::TypedCache::Namespace) }
@@ -48,24 +60,14 @@ module TypedCache
48
60
  sig { params(ns: T.any(::TypedCache::Namespace, String, T::Array[String])).returns(::TypedCache::Store[CachedType]) }
49
61
  def with_namespace(ns); end
50
62
 
51
- sig { returns(String) }
52
- def store_type; end
53
-
54
- sig { returns(T.self_type) }
55
- def clone; end
56
-
57
- sig { params(key: Key).returns(::TypedCache::CacheKey) }
58
- def namespaced_key(key); end
59
-
60
- sig { returns(::TypedCache::Instrumenter) }
61
- def instrumenter; end
62
-
63
- protected
64
-
65
- sig { params(string: String).returns(String) }
66
- def snake_case(string); end
67
-
68
- sig { params(namespace: ::TypedCache::Namespace).returns(::TypedCache::Namespace) }
69
- def nested_namespace(namespace); end
63
+ sig { params(ns: T.any(::TypedCache::Namespace, String, T::Array[String])).returns(::TypedCache::Store[CachedType]) }
64
+ def at_namespace(ns); end
65
+
66
+ sig do
67
+ type_parameters(:T)
68
+ .params(klass: T::Class[T.type_parameter(:T)], at: T.nilable(T.any(::TypedCache::Namespace, String)))
69
+ .returns(::TypedCache::Store[T.type_parameter(:T)])
70
+ end
71
+ def cache_for(klass, at: T.unsafe(nil)); end
70
72
  end
71
73
  end
data/rbi/typed_cache.rbi CHANGED
@@ -32,7 +32,7 @@ module TypedCache
32
32
  sig { returns(::TypedCache::Private::Configuration) }
33
33
  def config; end
34
34
 
35
- sig { returns(::TypedCache::CacheBuilder) }
35
+ sig { returns(::TypedCache::CacheDefinition) }
36
36
  def builder; end
37
37
 
38
38
  sig { returns(T.class_of(::TypedCache::Backends)) }
@@ -10,8 +10,74 @@ module TypedCache
10
10
  # that actually persist data.
11
11
  # @rbs generic V
12
12
  module Backend[V]
13
- include Store[V]
13
+ type cache_key = String | CacheKey
14
14
 
15
- include Store::_Store[V]
15
+ interface _Backend[V]
16
+ def read: (cache_key, **top) -> V?
17
+
18
+ def read_multi: (Array[cache_key], **top) -> Hash[cache_key, V]
19
+
20
+ def write: (cache_key, V, **top) -> V
21
+
22
+ def write_multi: (Hash[cache_key, V], **top) -> Hash[cache_key, V]
23
+
24
+ def delete: (cache_key) -> V?
25
+
26
+ def key?: (cache_key) -> bool
27
+
28
+ def clear: () -> void
29
+
30
+ def fetch: (cache_key, **top) { () -> V? } -> V?
31
+
32
+ def fetch_multi: (Array[cache_key], **top) { (cache_key) -> V? } -> Hash[cache_key, V]
33
+ end
34
+
35
+ include _Backend[V]
36
+
37
+ # @rbs override
38
+ # @rbs (cache_key, **top) -> V?
39
+ def read: ...
40
+
41
+ # @rbs override
42
+ # @rbs (Array[cache_key], **top) -> Hash[cache_key, V]
43
+ def read_multi: ...
44
+
45
+ # @rbs override
46
+ # @rbs (cache_key, V, **top) -> V
47
+ def write: ...
48
+
49
+ # @rbs override
50
+ # @rbs (Hash[cache_key, V], **top) -> Hash[cache_key, V]
51
+ def write_multi: ...
52
+
53
+ # @rbs override
54
+ # @rbs (cache_key) -> V?
55
+ def delete: ...
56
+
57
+ # @rbs override
58
+ # @rbs (cache_key) -> bool
59
+ def key?: ...
60
+
61
+ # @rbs override
62
+ # @rbs () -> void
63
+ def clear: ...
64
+
65
+ # @rbs override
66
+ # @rbs (cache_key, **top) { () -> V? } -> V?
67
+ def fetch: ...
68
+
69
+ # @rbs override
70
+ # @rbs (Array[cache_key], **top) { (cache_key) -> V? } -> Hash[cache_key, V]
71
+ def fetch_multi: ...
72
+
73
+ # @rbs override
74
+ # @rbs () -> String
75
+ def to_s: ...
76
+
77
+ # @rbs override
78
+ # @rbs () -> String
79
+ def inspect: ...
16
80
  end
81
+
82
+ type backend[V] = Backend::_Backend[V]
17
83
  end
@@ -7,37 +7,39 @@ module TypedCache
7
7
  class ActiveSupport[V]
8
8
  include Backend[V]
9
9
 
10
- attr_reader namespace: Namespace
11
-
12
10
  attr_reader cache_store: ::ActiveSupport::Cache::Store
13
11
 
14
12
  attr_reader default_options: Hash[Symbol, top]
15
13
 
16
- # : (Namespace, ::ActiveSupport::Cache::Store, ?Hash[Symbol, top]) -> void
17
- def initialize: (Namespace, ::ActiveSupport::Cache::Store, ?Hash[Symbol, top]) -> void
14
+ # : (::ActiveSupport::Cache::Store, ?Hash[Symbol, top]) -> void
15
+ def initialize: (::ActiveSupport::Cache::Store, ?Hash[Symbol, top]) -> void
18
16
 
19
17
  # @rbs override
20
- # : (cache_key) -> either[Error, Snapshot[V]]
18
+ # : (cache_key, **top) -> V?
21
19
  def read: ...
22
20
 
23
21
  # @rbs override
24
- # : (cache_key, V) -> either[Error, Snapshot[V]]
22
+ # : (cache_key, V, **top) -> V
25
23
  def write: ...
26
24
 
27
25
  # @rbs override
28
- # : (Hash[cache_key, V]) -> either[Error, Array[Snapshot[V]]]
26
+ # : (Hash[cache_key, V], **top) -> Array[V]
29
27
  def write_all: ...
30
28
 
31
29
  # @rbs override
32
- # : (cache_key) -> either[Error, Snapshot[V]]
30
+ # : (cache_key) -> V?
33
31
  def delete: ...
34
32
 
35
33
  # @rbs override
36
- # : (Array[cache_key]) -> either[Error, Array[Snapshot[V]]]
34
+ # : (Array[cache_key], **top) -> Hash[cache_key, V]
37
35
  def read_all: ...
38
36
 
39
37
  # @rbs override
40
- # : (Array[cache_key]) { (CacheKey) -> V? } -> either[Error, Array[Snapshot[V]]]
38
+ # : (cache_key, **top) { () -> V? } -> V?
39
+ def fetch: ...
40
+
41
+ # @rbs override
42
+ # : (Array[cache_key], **top) { (CacheKey) -> V? } -> Hash[cache_key, V]
41
43
  def fetch_all: ...
42
44
 
43
45
  # @rbs override
@@ -45,24 +47,14 @@ module TypedCache
45
47
  def key?: ...
46
48
 
47
49
  # @rbs override
48
- # : -> maybe[Error]
50
+ # : -> void
49
51
  def clear: ...
50
52
 
51
- # @rbs override
52
- # : -> String
53
- def store_type: ...
54
-
55
53
  # : (Hash[Symbol, top]) -> ActiveSupport[V]
56
54
  def with_options: (Hash[Symbol, top]) -> ActiveSupport[V]
57
55
 
58
56
  # : -> ::ActiveSupport::Cache::Store
59
57
  def raw_cache: () -> ::ActiveSupport::Cache::Store
60
-
61
- private
62
-
63
- # Regex patterns that match keys for this namespace (with trailing colon)
64
- # : -> Array[Regexp]
65
- def namespace_prefix_patterns: () -> Array[Regexp]
66
58
  end
67
59
  end
68
60
  end
@@ -1,15 +1,6 @@
1
1
  # Generated from lib/typed_cache/backends/memory.rb with RBS::Inline
2
2
 
3
3
  module TypedCache
4
- class MemoryStoreRegistry
5
- include Singleton
6
-
7
- extend Forwardable
8
-
9
- # : -> void
10
- def initialize: () -> void
11
- end
12
-
13
4
  module Backends
14
5
  # A type-safe memory store implementation with built-in namespacing
15
6
  # @rbs generic V
@@ -44,25 +35,23 @@ module TypedCache
44
35
  def expired?: () -> bool
45
36
  end
46
37
 
47
- attr_reader namespace: Namespace
48
-
49
- attr_reader ttl: Namespace
38
+ attr_reader ttl: Integer
50
39
 
51
- attr_reader backing_store: hash_like[CacheKey, Entry[V]]
40
+ attr_reader backing_store: hash_like[String, Entry[V]]
52
41
 
53
- # : (Namespace, shared: bool, ttl: Integer) -> void
54
- def initialize: (Namespace, shared: bool, ttl: Integer) -> void
42
+ # : (ttl: Integer) -> void
43
+ def initialize: (ttl: Integer) -> void
55
44
 
56
45
  # @rbs override
57
- # : (cache_key) -> either[Error, Snapshot[V]]
46
+ # : (cache_key, **top) -> V?
58
47
  def read: ...
59
48
 
60
49
  # @rbs override
61
- # : (cache_key, V) -> either[Error, Snapshot[V]]
50
+ # : (cache_key, V, expires_in: Integer, expires_at: Time, **top) -> V
62
51
  def write: ...
63
52
 
64
53
  # @rbs override
65
- # : (cache_key) -> either[Error, Snapshot[V]]
54
+ # : (cache_key) -> V?
66
55
  def delete: ...
67
56
 
68
57
  # @rbs override
@@ -70,24 +59,15 @@ module TypedCache
70
59
  def key?: ...
71
60
 
72
61
  # @rbs override
73
- # : -> maybe[Error]
62
+ # : -> void
74
63
  def clear: ...
75
64
 
76
65
  # @rbs override
77
- # : -> String
78
- def store_type: ...
79
-
80
- # : -> Integer
81
- def size: () -> Integer
82
-
83
- # : -> Array[CacheKey]
84
- def keys: () -> Array[CacheKey]
66
+ # : (cache_key, ttl: Integer, **top) { () -> V? } -> V?
67
+ def fetch: ...
85
68
 
86
69
  private
87
70
 
88
- # : -> Hash[CacheKey, Entry[V]]
89
- def namespaced_entries: () -> Hash[CacheKey, Entry[V]]
90
-
91
71
  # : -> void
92
72
  def purge_expired_keys: () -> void
93
73
  end
@@ -4,7 +4,7 @@ module TypedCache
4
4
  module Backends
5
5
  # @api private
6
6
  # Backend registry using composition
7
- REGISTRY: untyped
7
+ REGISTRY: Registry[Backend]
8
8
 
9
9
  extend Forwardable
10
10
 
@@ -12,7 +12,7 @@ module TypedCache
12
12
  # : -> Registry
13
13
  def self.registry: () -> Registry
14
14
 
15
- def resolve: (Symbol, *untyped, **untyped) -> either[Error, Store[untyped]]
15
+ def resolve: (Symbol, *untyped, **untyped) -> either[Error, Backend[untyped]]
16
16
 
17
17
  def available: () -> Array[Symbol]
18
18
 
@@ -1,23 +1,63 @@
1
1
  # Generated from lib/typed_cache/cache_builder.rb with RBS::Inline
2
2
 
3
3
  module TypedCache
4
- class CacheBuilder
5
- type config = TypedCache::typed_cache_config
4
+ class BackendConfig < Dry::Struct
5
+ end
6
+
7
+ class DecoratorConfig < Dry::Struct
8
+ end
9
+
10
+ class CacheDefinition
11
+ include _CacheDefinition
6
12
 
7
13
  type instrumenter_source = :default | :dry | :rails | Instrumenter
8
14
 
9
- class BackendConfig < Dry::Struct
10
- end
15
+ attr_reader backend_config: BackendConfig?
11
16
 
12
- class DecoratorConfig < Dry::Struct
13
- end
17
+ attr_reader decorator_configs: Array[DecoratorConfig]
14
18
 
15
- # @rbs (config, Registry[backend[untyped]], Registry[decorator[untyped]]) -> void
16
- def initialize: (config, Registry[backend[untyped]], Registry[decorator[untyped]]) -> void
19
+ attr_reader instrumenter_source: instrumenter_source
17
20
 
18
- # Builds the cache - the only method that can fail
19
- # @rbs (?Namespace) -> either[Error, Store[V]]
20
- def build: (?Namespace) -> either[Error, Store[V]]
21
+ # @rbs (?BackendConfig?, ?Array[DecoratorConfig], ?instrumenter_source) -> void
22
+ def initialize: (?BackendConfig?, ?Array[DecoratorConfig], ?instrumenter_source) -> void
23
+
24
+ # @rbs override
25
+ # @rbs (Symbol, *untyped, **untyped) -> self
26
+ def with_backend: ...
27
+
28
+ # @rbs override
29
+ # @rbs (Symbol, **untyped) -> self
30
+ def with_decorator: ...
31
+
32
+ # @rbs override
33
+ # @rbs (instrumenter_source) -> self
34
+ def with_instrumentation: ...
35
+ end
36
+
37
+ class CacheBuilder
38
+ include _CacheBuilder
39
+
40
+ include _CacheDefinition
41
+
42
+ # @rbs (?_CacheDefinition, ?Registry[backend[untyped]], ?Registry[decorator[untyped]]) -> void
43
+ def initialize: (?_CacheDefinition, ?Registry[backend[untyped]], ?Registry[decorator[untyped]]) -> void
44
+
45
+ # Builds the cache using the given namespace, defaulting to the root namespace
46
+ # @rbs (?Namespace) -> either[Error, Store[untyped]]
47
+ def build: (?Namespace) -> either[Error, Store[untyped]]
48
+
49
+ # @rbs (Namespace) -> Store[untyped]
50
+ def build!: (Namespace) -> Store[untyped]
51
+
52
+ # Constructs only a typed backend from the registry without a Store wrapper
53
+ # @rbs () -> either[Error, Backend[untyped]]
54
+ def build_backend: () -> either[Error, Backend[untyped]]
55
+
56
+ # Constructs only a typed backend from the registry without a Store wrapper,
57
+ # raises an error if the backend cannot be constructed
58
+ #
59
+ # @rbs () -> Backend[untyped]
60
+ def build_backend!: () -> Backend[untyped]
21
61
 
22
62
  # Familiar Ruby fluent interface - always succeeds
23
63
  # Invalid configurations are caught during build()
@@ -37,12 +77,13 @@ module TypedCache
37
77
  # @rbs (Namespace) -> either[Error, Store[V]]
38
78
  def validate_and_build: (Namespace) -> either[Error, Store[V]]
39
79
 
40
- # @rbs (Namespace) -> either[Error, Store[V]]
41
- def create_store: (Namespace) -> either[Error, Store[V]]
80
+ # @rbs (Namespace) -> either[Error, Backend[untyped]]
81
+ def create_backend: (Namespace) -> either[Error, Backend[untyped]]
42
82
 
43
- # @rbs (Store[V]) -> either[Error, Store[V]]
44
- def apply_decorators: (Store[V]) -> either[Error, Store[V]]
83
+ # @rbs (Backend[untyped]) -> either[Error, Decorator[untyped]]
84
+ def apply_decorators: (Backend[untyped]) -> either[Error, Decorator[untyped]]
45
85
 
46
- def apply_instrumentation: (untyped store) -> untyped
86
+ # @rbs (Backend[untyped]) -> either[Error, Backend[untyped]]
87
+ def apply_instrumentation: (Backend[untyped]) -> either[Error, Backend[untyped]]
47
88
  end
48
89
  end
@@ -15,21 +15,21 @@ module TypedCache
15
15
  def initialize: (Store[V], CacheKey) -> void
16
16
 
17
17
  # Gets a value from the cache as a snapshot
18
- # : -> either[Error, Snapshot[V]]
19
- def read: () -> either[Error, Snapshot[V]]
18
+ # : -> either[Error, Snapshot[maybe[V]]]
19
+ def read: () -> either[Error, Snapshot[maybe[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
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
- # : -> either[Error, Snapshot[V]]
27
- def delete: () -> either[Error, Snapshot[V]]
26
+ # : -> either[Error, maybe[V]]
27
+ def delete: () -> either[Error, maybe[V]]
28
28
 
29
29
  # Fetches a value from cache, computing and storing it if not found
30
30
  # The snapshot indicates whether the value came from cache or was computed
31
- # : () { -> V } -> either[Error, Snapshot[V]]
32
- def fetch: () { () -> V } -> either[Error, Snapshot[V]]
31
+ # : () { -> V? } -> either[Error, Snapshot[maybe[V]]]
32
+ def fetch: () { () -> V? } -> either[Error, Snapshot[maybe[V]]]
33
33
 
34
34
  # Checks if the cache contains a value for this key
35
35
  # : -> bool
@@ -43,42 +43,15 @@ module TypedCache
43
43
  # : [R] () { (V) -> R } -> either[Error, Snapshot[R]]
44
44
  def map: [R] () { (V) -> R } -> either[Error, Snapshot[R]]
45
45
 
46
- # Binds over the cached value, allowing for monadic composition with snapshots
47
- # : [R] () { (V) -> either[Error, R] } -> either[Error, Snapshot[R]]
48
- def bind: [R] () { (V) -> either[Error, R] } -> either[Error, Snapshot[R]]
49
-
50
- alias flat_map bind
51
-
52
46
  # Updates the cached value using the provided block
53
47
  # Returns the updated value as a snapshot with source=:updated
54
- # : () { (V) -> V } -> either[Error, Snapshot[V]]
55
- def update: () { (V) -> V } -> either[Error, Snapshot[V]]
56
-
57
- # Returns the cached value or a default if the cache is empty/errored
58
- # : (V) -> V
59
- def value_or: (V) -> V
60
-
61
- # Returns a Maybe containing the cached value, or None if not present
62
- # This provides a more functional approach than value_or
63
- # : -> maybe[V]
64
- def value_maybe: () -> maybe[V]
48
+ # : () { (V) -> V? } -> either[Error, Snapshot[maybe[V]]]
49
+ def update: () { (V) -> V? } -> either[Error, Snapshot[maybe[V]]]
65
50
 
66
51
  # Computes and caches a value if the cache is currently empty
67
52
  # Returns existing snapshot if present, computed snapshot if cache miss, error otherwise
68
- # : () { -> V } -> either[Error, Snapshot[V]]
69
- def compute_if_absent: () { () -> V } -> either[Error, Snapshot[V]]
70
-
71
- # Creates a new CacheRef with the same store but different key
72
- # : [R] (String) -> CacheRef[R]
73
- def with_key: [R] (String) -> CacheRef[R]
74
-
75
- # Creates a scoped CacheRef by appending to the current key path
76
- # : [R] (String) -> CacheRef[R]
77
- def scope: [R] (String) -> CacheRef[R]
78
-
79
- # Pattern matching support for Either[Error, Snapshot[V]] results
80
- # : [R] (^(Error) -> R, ^(Snapshot[V]) -> R) -> R
81
- def fold: [R] (^(Error) -> R, ^(Snapshot[V]) -> R) -> R
53
+ # : () { -> V? } -> either[Error, Snapshot[maybe[V]]]
54
+ def compute_if_absent: () { () -> V? } -> either[Error, Snapshot[maybe[V]]]
82
55
 
83
56
  # Convenience method to work with the snapshot directly
84
57
  # : [R] () { (Snapshot[V]) -> R } -> either[Error, R]
@@ -87,5 +60,11 @@ module TypedCache
87
60
  # Convenience method to work with just the value (losing snapshot context)
88
61
  # : [R] () { (V) -> R } -> either[Error, R]
89
62
  def with: [R] () { (V) -> R } -> either[Error, R]
63
+
64
+ # @rbs () -> String
65
+ def to_s: () -> String
66
+
67
+ # @rbs () -> String
68
+ def inspect: () -> String
90
69
  end
91
70
  end
@@ -7,20 +7,32 @@ module TypedCache
7
7
  module Decorator[V]
8
8
  extend Forwardable
9
9
 
10
- include Store[V]
10
+ interface _Decorator[V]
11
+ def initialize: (Backend[V]) -> void
12
+ end
11
13
 
12
- include Store::_Store[V]
14
+ include Backend[V]
13
15
 
14
- include Store::_Decorator[V]
16
+ include Backend::_Backend[V]
15
17
 
16
- def store: () -> Store[V]
18
+ include _Decorator[V]
17
19
 
18
20
  # @rbs override
19
- # : (cache_key) -> either[Error, CacheRef[V]]
20
- def ref: ...
21
+ # @rbs () -> Backend[V]
22
+ def backend: ...
21
23
 
22
24
  # @rbs override
23
25
  # : (self) -> void
24
26
  def initialize_copy: ...
27
+
28
+ # @rbs override
29
+ # @rbs () -> String
30
+ def to_s: ...
31
+
32
+ # @rbs override
33
+ # @rbs () -> String
34
+ def inspect: ...
25
35
  end
36
+
37
+ type decorator[V] = Decorator::_Decorator[V] & Backend[V]
26
38
  end
@@ -9,24 +9,20 @@ module TypedCache
9
9
 
10
10
  extend Forwardable
11
11
 
12
- attr_reader store: TypedCache::Store[V]
12
+ attr_reader backend: Backend[V]
13
13
 
14
14
  attr_reader instrumenter: Instrumenter
15
15
 
16
16
  # @rbs (Symbol, ?operation: String) ?{ (*untyped, **untyped) -> String } -> void
17
17
  private def self.instrument: (Symbol, ?operation: String) ?{ (*untyped, **untyped) -> String } -> void
18
18
 
19
- # : (TypedCache::Store[V], instrumenter: Instrumenter) -> void
20
- def initialize: (TypedCache::Store[V], instrumenter: Instrumenter) -> void
19
+ # : (Backend[V], instrumenter: Instrumenter) -> void
20
+ def initialize: (Backend[V], instrumenter: Instrumenter) -> void
21
21
 
22
22
  # @rbs override
23
23
  # : (self) -> self
24
24
  def initialize_copy: ...
25
25
 
26
- # @rbs override
27
- # : -> String
28
- def store_type: ...
29
-
30
26
  # Additional methods that might exist on the wrapped store
31
27
  def respond_to_missing?: (untyped method_name, ?untyped include_private) -> untyped
32
28
 
@@ -16,10 +16,18 @@ module TypedCache
16
16
  # @api private
17
17
  # Default decorator set – starts with instrumentation only, but this registry
18
18
  # lets end-users register their own via `Decorators.register`.
19
- REGISTRY: untyped
19
+ REGISTRY: Registry[Decorator]
20
20
 
21
21
  extend Forwardable
22
22
 
23
+ def resolve: (Symbol, *untyped, **untyped) -> either[Error, Decorator[untyped]]
24
+
25
+ def available: () -> Array[Symbol]
26
+
27
+ def register: (Symbol, Class) -> either[Error, void]
28
+
29
+ def registered?: (Symbol) -> bool
30
+
23
31
  # @api private
24
32
  # @rbs () -> Registry[Store[untyped]]
25
33
  def self.registry: () -> Registry[Store[untyped]]