typed_cache 0.3.2 → 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.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/lib/typed_cache/backend.rb +80 -2
- data/lib/typed_cache/backends/active_support.rb +24 -98
- data/lib/typed_cache/backends/memory.rb +22 -73
- data/lib/typed_cache/backends.rb +2 -2
- data/lib/typed_cache/cache_builder.rb +131 -46
- data/lib/typed_cache/cache_key.rb +1 -1
- data/lib/typed_cache/cache_ref.rb +24 -55
- data/lib/typed_cache/decorator.rb +22 -12
- data/lib/typed_cache/decorators/instrumented.rb +12 -19
- data/lib/typed_cache/decorators.rb +7 -1
- data/lib/typed_cache/either.rb +28 -0
- data/lib/typed_cache/instrumenters.rb +6 -2
- data/lib/typed_cache/maybe.rb +28 -0
- data/lib/typed_cache/namespace.rb +1 -3
- data/lib/typed_cache/snapshot.rb +6 -0
- data/lib/typed_cache/store.rb +130 -78
- data/lib/typed_cache/version.rb +1 -1
- data/lib/typed_cache.rb +5 -2
- data/rbi/typed_cache/backend.rbi +44 -2
- data/rbi/typed_cache/backends/active_support.rbi +1 -1
- data/rbi/typed_cache/backends/memory.rbi +1 -1
- data/rbi/typed_cache/cache_builder.rbi +29 -10
- data/rbi/typed_cache/cache_key.rbi +14 -0
- data/rbi/typed_cache/cache_ref.rbi +6 -15
- data/rbi/typed_cache/decorator.rbi +23 -37
- data/rbi/typed_cache/decorators/instrumented.rbi +1 -1
- data/rbi/typed_cache/either.rbi +24 -0
- data/rbi/typed_cache/maybe.rbi +24 -0
- data/rbi/typed_cache/namespace.rbi +14 -0
- data/rbi/typed_cache/snapshot.rbi +6 -0
- data/rbi/typed_cache/store.rbi +26 -24
- data/rbi/typed_cache.rbi +1 -1
- data/sig/generated/typed_cache/backend.rbs +68 -2
- data/sig/generated/typed_cache/backends/active_support.rbs +13 -21
- data/sig/generated/typed_cache/backends/memory.rbs +10 -30
- data/sig/generated/typed_cache/backends.rbs +2 -2
- data/sig/generated/typed_cache/cache_builder.rbs +57 -16
- data/sig/generated/typed_cache/cache_ref.rbs +16 -37
- data/sig/generated/typed_cache/decorator.rbs +18 -6
- data/sig/generated/typed_cache/decorators/instrumented.rbs +3 -7
- data/sig/generated/typed_cache/decorators.rbs +9 -1
- data/sig/generated/typed_cache/either.rbs +24 -0
- data/sig/generated/typed_cache/instrumenters.rbs +4 -3
- data/sig/generated/typed_cache/maybe.rbs +24 -0
- data/sig/generated/typed_cache/namespace.rbs +0 -2
- data/sig/generated/typed_cache/snapshot.rbs +6 -0
- data/sig/generated/typed_cache/store.rbs +47 -40
- data/sig/generated/typed_cache.rbs +6 -2
- data.tar.gz.sig +0 -0
- metadata +3 -3
- metadata.gz.sig +0 -0
@@ -79,6 +79,18 @@ module TypedCache
|
|
79
79
|
|
80
80
|
# : (Array[top]) -> ({ error: E })
|
81
81
|
def deconstruct_keys: (Array[top]) -> { error: E }
|
82
|
+
|
83
|
+
# @rbs (other: Object) -> bool
|
84
|
+
def ==: (other: Object) -> bool
|
85
|
+
|
86
|
+
# @rbs () -> Integer
|
87
|
+
def hash: () -> Integer
|
88
|
+
|
89
|
+
# @rbs () -> String
|
90
|
+
def to_s: () -> String
|
91
|
+
|
92
|
+
# @rbs () -> String
|
93
|
+
def inspect: () -> String
|
82
94
|
end
|
83
95
|
|
84
96
|
# @rbs generic out R
|
@@ -126,5 +138,17 @@ module TypedCache
|
|
126
138
|
|
127
139
|
# : (Array[top]) -> ({ value: R })
|
128
140
|
def deconstruct_keys: (Array[top]) -> { value: R }
|
141
|
+
|
142
|
+
# @rbs (other: Object) -> bool
|
143
|
+
def ==: (other: Object) -> bool
|
144
|
+
|
145
|
+
# @rbs () -> Integer
|
146
|
+
def hash: () -> Integer
|
147
|
+
|
148
|
+
# @rbs () -> String
|
149
|
+
def to_s: () -> String
|
150
|
+
|
151
|
+
# @rbs () -> String
|
152
|
+
def inspect: () -> String
|
129
153
|
end
|
130
154
|
end
|
@@ -7,7 +7,7 @@ module TypedCache
|
|
7
7
|
# Registry class directly because many instrumenters mix in `Singleton`,
|
8
8
|
# making `.new` inaccessible. Instead we implement a thin facade that
|
9
9
|
# returns either the singleton instance (preferred) or a fresh instance.
|
10
|
-
REGISTRY: Registry[
|
10
|
+
REGISTRY: Registry[Instrumenter]
|
11
11
|
|
12
12
|
extend Forwardable
|
13
13
|
|
@@ -15,9 +15,10 @@ module TypedCache
|
|
15
15
|
# @rbs () -> Registry[Symbol, Class[Instrumenter]]
|
16
16
|
def self.registry: () -> Registry[Symbol, Class[Instrumenter]]
|
17
17
|
|
18
|
-
|
18
|
+
# @rbs (Symbol, ?namespace: String, **untyped) -> either[Error, Instrumenter]
|
19
|
+
def self.resolve: (Symbol, ?namespace: String, **untyped) -> either[Error, Instrumenter]
|
19
20
|
|
20
|
-
def
|
21
|
+
def register: (Symbol, Class[Instrumenter]) -> void
|
21
22
|
|
22
23
|
def available: () -> Array[Symbol]
|
23
24
|
|
@@ -71,6 +71,18 @@ module TypedCache
|
|
71
71
|
|
72
72
|
# : (Array[top]) -> ({ value: V })
|
73
73
|
def deconstruct_keys: (Array[top]) -> { value: V }
|
74
|
+
|
75
|
+
# @rbs (other: Object) -> bool
|
76
|
+
def ==: (other: Object) -> bool
|
77
|
+
|
78
|
+
# @rbs () -> Integer
|
79
|
+
def hash: () -> Integer
|
80
|
+
|
81
|
+
# @rbs () -> String
|
82
|
+
def to_s: () -> String
|
83
|
+
|
84
|
+
# @rbs () -> String
|
85
|
+
def inspect: () -> String
|
74
86
|
end
|
75
87
|
|
76
88
|
class Nothing
|
@@ -101,5 +113,17 @@ module TypedCache
|
|
101
113
|
# @rbs override
|
102
114
|
# : -> V
|
103
115
|
def value_or_raise!: ...
|
116
|
+
|
117
|
+
# @rbs (other: Object) -> bool
|
118
|
+
def ==: (other: Object) -> bool
|
119
|
+
|
120
|
+
# @rbs () -> Integer
|
121
|
+
def hash: () -> Integer
|
122
|
+
|
123
|
+
# @rbs () -> String
|
124
|
+
def to_s: () -> String
|
125
|
+
|
126
|
+
# @rbs () -> String
|
127
|
+
def inspect: () -> String
|
104
128
|
end
|
105
129
|
end
|
@@ -41,6 +41,12 @@ module TypedCache
|
|
41
41
|
|
42
42
|
alias flat_map bind
|
43
43
|
|
44
|
+
# @rbs () -> String
|
45
|
+
def to_s: () -> String
|
46
|
+
|
47
|
+
# @rbs () -> String
|
48
|
+
def inspect: () -> String
|
49
|
+
|
44
50
|
# Creates a snapshot for a cached value
|
45
51
|
# : [V] (CacheKey, V) -> Snapshot[V]
|
46
52
|
def self.cached: [V] (CacheKey, V) -> Snapshot[V]
|
@@ -9,52 +9,61 @@ module TypedCache
|
|
9
9
|
# - Queries (get, key?, fetch) ask questions without side effects
|
10
10
|
#
|
11
11
|
# @rbs generic V
|
12
|
-
|
12
|
+
class Store[V]
|
13
13
|
type cache_key = String | CacheKey
|
14
14
|
|
15
15
|
interface _Store[V]
|
16
|
-
def read: (cache_key) -> either[Error, Snapshot[V]]
|
16
|
+
def read: (cache_key) -> either[Error, Snapshot[maybe[V]]]
|
17
17
|
|
18
|
-
def read_all: (Array[cache_key]) -> either[Error,
|
18
|
+
def read_all: (Array[cache_key]) -> either[Error, Hash[CacheKey, Snapshot[V]]]
|
19
19
|
|
20
20
|
def ref: (cache_key) -> CacheRef[V]
|
21
21
|
|
22
22
|
def write: (cache_key, V) -> either[Error, Snapshot[V]]
|
23
23
|
|
24
|
-
def write_all: (Hash[cache_key, V]) -> either[Error,
|
24
|
+
def write_all: (Hash[cache_key, V]) -> either[Error, Hash[CacheKey, Snapshot[V]]]
|
25
25
|
|
26
|
-
def delete: (cache_key) -> either[Error,
|
26
|
+
def delete: (cache_key) -> either[Error, maybe[V]]
|
27
27
|
|
28
28
|
def key?: (cache_key) -> bool
|
29
29
|
|
30
|
-
def clear: () ->
|
30
|
+
def clear: () -> void
|
31
31
|
|
32
|
-
def fetch: (cache_key) { () -> V? } -> either[Error, Snapshot[maybe[V]]]
|
32
|
+
def fetch: (cache_key) { (CacheKey) -> V? } -> either[Error, Snapshot[maybe[V]]]
|
33
33
|
|
34
34
|
def fetch_all: (Array[cache_key]) { (CacheKey) -> V? } -> either[Error, Array[Snapshot[V]]]
|
35
35
|
|
36
|
+
def fetch_or_compute_all: (Array[cache_key]) { (Array[CacheKey]) -> Hash[CacheKey, V] } -> either[Error, Hash[CacheKey, Snapshot[V]]]
|
37
|
+
|
36
38
|
def namespace: () -> Namespace
|
37
39
|
|
38
40
|
def with_namespace: (Namespace) -> Store[V]
|
39
41
|
|
40
|
-
def
|
42
|
+
def at_namespace: (Namespace) -> Store[V]
|
43
|
+
|
44
|
+
def cache_for: [T] (Class[T], at: Namespace | String | Array[String]) -> Store[T]
|
45
|
+
|
46
|
+
def backend: () -> Backend[V]
|
41
47
|
end
|
42
48
|
|
43
49
|
include _Store[V]
|
44
50
|
|
45
|
-
|
46
|
-
|
47
|
-
|
51
|
+
attr_reader namespace: Namespace
|
52
|
+
|
53
|
+
attr_reader backend: Backend[V]
|
54
|
+
|
55
|
+
# @rbs (Namespace, Backend[V]) -> void
|
56
|
+
def initialize: (Namespace, Backend[V]) -> void
|
48
57
|
|
49
58
|
# @rbs (Store[V]) -> void
|
50
59
|
def initialize_copy: (Store[V]) -> void
|
51
60
|
|
52
61
|
# Retrieves a value from the cache
|
53
|
-
# @rbs (cache_key, **top) -> either[Error, Snapshot[V]]
|
54
|
-
def read: (cache_key, **top) -> either[Error, Snapshot[V]]
|
62
|
+
# @rbs (cache_key, **top) -> either[Error, Snapshot[maybe[V]]]
|
63
|
+
def read: (cache_key, **top) -> either[Error, Snapshot[maybe[V]]]
|
55
64
|
|
56
|
-
# @rbs (Array[cache_key], **top) -> either[Error, Hash[
|
57
|
-
def read_all: (Array[cache_key], **top) -> either[Error, Hash[
|
65
|
+
# @rbs (Array[cache_key], **top) -> either[Error, Hash[CacheKey, Snapshot[V]]]
|
66
|
+
def read_all: (Array[cache_key], **top) -> either[Error, Hash[CacheKey, Snapshot[V]]]
|
58
67
|
|
59
68
|
# Retrieves a cache reference for a key
|
60
69
|
# @rbs (cache_key) -> CacheRef[V]
|
@@ -64,59 +73,57 @@ module TypedCache
|
|
64
73
|
# @rbs (cache_key, V, **top) -> either[Error, Snapshot[V]]
|
65
74
|
def write: (cache_key, V, **top) -> either[Error, Snapshot[V]]
|
66
75
|
|
67
|
-
|
68
|
-
def write_all: (Hash[cache_key, V], **top) -> either[Error, Hash[cache_key, Snapshot[V]]]
|
76
|
+
def write_all: (untyped values, **untyped kwargs) -> untyped
|
69
77
|
|
70
78
|
# Removes a value from the cache, returning the removed value
|
71
|
-
# @rbs (cache_key) -> either[Error,
|
72
|
-
def delete: (cache_key) -> either[Error,
|
79
|
+
# @rbs (cache_key) -> either[Error, maybe[V]]
|
80
|
+
def delete: (cache_key) -> either[Error, maybe[V]]
|
73
81
|
|
74
82
|
# Checks if a key exists in the cache (query operation)
|
75
83
|
# @rbs (cache_key) -> bool
|
76
84
|
def key?: (cache_key) -> bool
|
77
85
|
|
78
86
|
# Clears all values from the cache namespace (command operation)
|
79
|
-
# @rbs () ->
|
80
|
-
def clear: () ->
|
87
|
+
# @rbs () -> void
|
88
|
+
def clear: () -> void
|
81
89
|
|
82
90
|
# Fetches a value from cache, computing and storing it if not found
|
83
91
|
# This is an atomic operation that combines read and write
|
84
|
-
# @rbs (cache_key, **top) { () -> V } -> either[Error, Snapshot[V]]
|
85
|
-
def fetch: (cache_key, **top) { () -> V } -> either[Error, Snapshot[V]]
|
92
|
+
# @rbs (cache_key, **top) { (CacheKey) -> V? } -> either[Error, Snapshot[maybe[V]]]
|
93
|
+
def fetch: (cache_key, **top) { (CacheKey) -> V? } -> either[Error, Snapshot[maybe[V]]]
|
86
94
|
|
87
|
-
# @rbs (Array[cache_key], **top) { (CacheKey) -> V } -> either[Error,
|
88
|
-
def fetch_all: (Array[cache_key], **top) { (CacheKey) -> V } -> either[Error,
|
95
|
+
# @rbs (Array[cache_key], **top) { (CacheKey) -> V? } -> either[Error, Hash[CacheKey, Snapshot[V]]]
|
96
|
+
def fetch_all: (Array[cache_key], **top) { (CacheKey) -> V? } -> either[Error, Hash[CacheKey, Snapshot[V]]]
|
97
|
+
|
98
|
+
# @rbs (Array[cache_key], **top) { (Array[CacheKey]) -> Hash[CacheKey, V] } -> either[Error, Hash[CacheKey, Snapshot[V]]]
|
99
|
+
def fetch_or_compute_all: (Array[cache_key], **top) { (Array[CacheKey]) -> Hash[CacheKey, V] } -> either[Error, Hash[CacheKey, Snapshot[V]]]
|
89
100
|
|
90
101
|
# @rbs () -> Instrumenter
|
91
102
|
def instrumenter: () -> Instrumenter
|
92
103
|
|
93
|
-
# Returns the namespace for this store (for instrumentation/debugging)
|
94
|
-
# @rbs () -> Namespace
|
95
|
-
def namespace: () -> Namespace
|
96
|
-
|
97
104
|
# Accepts a String segment or a fully-formed Namespace and returns a cloned
|
98
105
|
# store scoped to that namespace.
|
99
106
|
# : (Namespace | String | Array[String]) -> Store[V]
|
100
107
|
def with_namespace: (Namespace | String | Array[String]) -> Store[V]
|
101
108
|
|
102
|
-
#
|
109
|
+
# @rbs [T] (Class[T], at: (Namespace | String | Array[String])) -> Store[T]
|
110
|
+
def cache_for: [T] (Class[T], at: Namespace | String | Array[String]) -> Store[T]
|
111
|
+
|
112
|
+
alias at_namespace with_namespace
|
113
|
+
|
103
114
|
# @rbs () -> String
|
104
|
-
def
|
115
|
+
def to_s: () -> String
|
105
116
|
|
106
|
-
|
117
|
+
# @rbs () -> String
|
118
|
+
def inspect: () -> String
|
107
119
|
|
108
|
-
|
120
|
+
attr_writer namespace: untyped
|
109
121
|
|
110
|
-
|
111
|
-
def snake_case: (String) -> String
|
122
|
+
private
|
112
123
|
|
113
124
|
# : (cache_key) -> CacheKey
|
114
125
|
def namespaced_key: (cache_key) -> CacheKey
|
115
126
|
end
|
116
127
|
|
117
|
-
type
|
118
|
-
|
119
|
-
type decorator[V] = backend[V] & Store::_Decorator[V]
|
120
|
-
|
121
|
-
type store[V] = backend[V] | decorator[V]
|
128
|
+
type store[V] = Store::_Store[V]
|
122
129
|
end
|
@@ -7,6 +7,8 @@ module TypedCache
|
|
7
7
|
def enabled: () -> bool
|
8
8
|
|
9
9
|
def namespace: () -> String
|
10
|
+
|
11
|
+
def instrumenter: () -> Symbol
|
10
12
|
end
|
11
13
|
|
12
14
|
interface _TypedCacheConfig
|
@@ -19,9 +21,11 @@ module TypedCache
|
|
19
21
|
|
20
22
|
type typed_cache_config = _TypedCacheConfig
|
21
23
|
|
24
|
+
type cache_definition = TypedCache::_CacheDefinition
|
25
|
+
|
22
26
|
# Returns a CacheBuilder with the fluent interface
|
23
|
-
# @rbs
|
24
|
-
def self.builder:
|
27
|
+
# @rbs () -> cache_definition
|
28
|
+
def self.builder: () -> cache_definition
|
25
29
|
|
26
30
|
def config: () -> _TypedCacheConfig
|
27
31
|
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: typed_cache
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0.pre.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Autumn Winter
|
@@ -35,7 +35,7 @@ cert_chain:
|
|
35
35
|
uuhUq525FXA3gYeLAfnCSHNm7D1H7whsXYd3z+gKvEhSEQPb3mSBQ+31TDFmA5k7
|
36
36
|
q7YL3dwhxKPXtnAboI+30XBImpdizFG9Nyqgzgj/kD0QwVzL0QsVdVWnNTJXrm4n
|
37
37
|
-----END CERTIFICATE-----
|
38
|
-
date: 2025-08-
|
38
|
+
date: 2025-08-18 00:00:00.000000000 Z
|
39
39
|
dependencies:
|
40
40
|
- !ruby/object:Gem::Dependency
|
41
41
|
name: concurrent-ruby
|
@@ -220,7 +220,7 @@ licenses:
|
|
220
220
|
- Apache-2.0
|
221
221
|
metadata:
|
222
222
|
issue_tracker_uri: https://github.com/glossawy/typed_cache/issues
|
223
|
-
changelog_uri: https://github.com/glossawy/typed_cache/blob/main/VERSIONS.adoc#
|
223
|
+
changelog_uri: https://github.com/glossawy/typed_cache/blob/main/VERSIONS.adoc#040-1
|
224
224
|
license_uri: https://github.com/glossawy/typed_cache/blob/main/LICENSE
|
225
225
|
label: caching
|
226
226
|
labels: typed_cache,ruby,caching,type-safety,rails,rbs
|
metadata.gz.sig
CHANGED
Binary file
|