@orieljs/cache 0.1.0-alpha.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.
- package/LICENSE +202 -0
- package/NOTICE +9 -0
- package/dist/index.d.ts +385 -0
- package/dist/index.js +1060 -0
- package/dist/index.js.map +1 -0
- package/package.json +40 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/NOTICE
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
Oriel
|
|
2
|
+
Copyright 2026 meeeet-dev and Oriel contributors
|
|
3
|
+
|
|
4
|
+
This product includes software developed by the Oriel project
|
|
5
|
+
(https://orieljs.vercel.app, https://github.com/orieljs).
|
|
6
|
+
|
|
7
|
+
Oriel is licensed under the Apache License, Version 2.0 (see LICENSE).
|
|
8
|
+
The Oriel name and logo are not covered by that license; see TRADEMARKS.md
|
|
9
|
+
(https://github.com/orieljs/framework/blob/main/TRADEMARKS.md).
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,385 @@
|
|
|
1
|
+
import * as _orieljs_contracts from '@orieljs/contracts';
|
|
2
|
+
import { OrielError, Lock, CacheRepository, DatabaseConnection, CacheManager as CacheManager$1, Container } from '@orieljs/contracts';
|
|
3
|
+
import Redis from 'ioredis';
|
|
4
|
+
import * as _orieljs_support from '@orieljs/support';
|
|
5
|
+
import { ServiceProvider } from '@orieljs/support';
|
|
6
|
+
|
|
7
|
+
declare class LockTimeoutError extends Error implements OrielError {
|
|
8
|
+
readonly lockName: string;
|
|
9
|
+
readonly kind: "Server";
|
|
10
|
+
readonly status = 500;
|
|
11
|
+
readonly name = "LockTimeoutError";
|
|
12
|
+
constructor(lockName: string);
|
|
13
|
+
}
|
|
14
|
+
declare class TagsNotSupportedError extends Error implements OrielError {
|
|
15
|
+
readonly kind: "Server";
|
|
16
|
+
readonly status = 500;
|
|
17
|
+
readonly name = "TagsNotSupportedError";
|
|
18
|
+
constructor(store: string);
|
|
19
|
+
}
|
|
20
|
+
declare class UnknownCacheStoreError extends Error implements OrielError {
|
|
21
|
+
readonly kind: "Server";
|
|
22
|
+
readonly status = 500;
|
|
23
|
+
readonly name = "UnknownCacheStoreError";
|
|
24
|
+
constructor(name: string);
|
|
25
|
+
}
|
|
26
|
+
declare class UnknownCacheDriverError extends Error implements OrielError {
|
|
27
|
+
readonly kind: "Server";
|
|
28
|
+
readonly status = 500;
|
|
29
|
+
readonly name = "UnknownCacheDriverError";
|
|
30
|
+
constructor(driver: string);
|
|
31
|
+
}
|
|
32
|
+
declare class InvalidCacheConfigError extends Error implements OrielError {
|
|
33
|
+
readonly kind: "Server";
|
|
34
|
+
readonly status = 500;
|
|
35
|
+
readonly name = "InvalidCacheConfigError";
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Cache values always round-trip through JSON.stringify/JSON.parse, on every store — even the in-process
|
|
40
|
+
* memory store — so switching `cache.default` never changes behaviour. Practical limits this implies:
|
|
41
|
+
* - A Date becomes a string (ISO 8601). Read it back with `new Date(...)`, or use a Model cast.
|
|
42
|
+
* - undefined properties on an object are dropped, and a bare `undefined` value is stored as `null` (it reads
|
|
43
|
+
* back as `null`, not as a miss: `undefined` is only ever the "cache miss" result of a read).
|
|
44
|
+
* - NaN and Infinity become `null`.
|
|
45
|
+
* - Map, Set, class instances, functions and symbols do not round-trip: plain data only.
|
|
46
|
+
*/
|
|
47
|
+
declare function serialize(value: unknown): string;
|
|
48
|
+
declare function deserialize(raw: string): unknown;
|
|
49
|
+
/** Deep-clones `value` through JSON, applying the same limits as every persisted store. */
|
|
50
|
+
declare function roundTrip<T>(value: T): T;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* The low-level storage primitive each driver implements. `Repository` builds the full CacheRepository API
|
|
54
|
+
* (many/has/missing/pull/remember/rememberForever/lock/tags) on top of these primitives — the same split as
|
|
55
|
+
* Laravel's `Illuminate\Contracts\Cache\Store` + `Illuminate\Cache\Repository`.
|
|
56
|
+
*/
|
|
57
|
+
interface Store {
|
|
58
|
+
/** undefined when the key is missing or expired. */
|
|
59
|
+
get(key: string): Promise<unknown>;
|
|
60
|
+
/** Only returns entries for keys that are present and unexpired. */
|
|
61
|
+
many(keys: string[]): Promise<Record<string, unknown>>;
|
|
62
|
+
/** seconds is always a positive, finite number: Repository handles undefined (forever) and <= 0 (forget) itself. */
|
|
63
|
+
put(key: string, value: unknown, seconds: number): Promise<boolean>;
|
|
64
|
+
putForever(key: string, value: unknown): Promise<boolean>;
|
|
65
|
+
/** Atomic: stores only if the key is missing or expired. undefined seconds means forever. */
|
|
66
|
+
add(key: string, value: unknown, seconds?: number): Promise<boolean>;
|
|
67
|
+
/** A missing key behaves as if it held 0: increment creates it at `by`, stored forever. An existing TTL is preserved. */
|
|
68
|
+
increment(key: string, by: number): Promise<number>;
|
|
69
|
+
decrement(key: string, by: number): Promise<number>;
|
|
70
|
+
forget(key: string): Promise<boolean>;
|
|
71
|
+
flush(): Promise<boolean>;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
type LockFactory = (store: Store, name: string, seconds: number | undefined, owner: string | undefined) => Lock;
|
|
75
|
+
declare const defaultLockFactory: LockFactory;
|
|
76
|
+
/** Implements the full CacheRepository API over any Store, the way Illuminate\Cache\Repository wraps a Store. */
|
|
77
|
+
declare class Repository implements CacheRepository {
|
|
78
|
+
protected readonly store: Store;
|
|
79
|
+
private readonly lockFactory;
|
|
80
|
+
constructor(store: Store, lockFactory?: LockFactory);
|
|
81
|
+
get<T = unknown>(key: string, defaultValue?: T | (() => T)): Promise<T | undefined>;
|
|
82
|
+
many<T = unknown>(keys: string[]): Promise<Record<string, T | undefined>>;
|
|
83
|
+
has(key: string): Promise<boolean>;
|
|
84
|
+
missing(key: string): Promise<boolean>;
|
|
85
|
+
put(key: string, value: unknown, ttlSeconds?: number): Promise<boolean>;
|
|
86
|
+
add(key: string, value: unknown, ttlSeconds?: number): Promise<boolean>;
|
|
87
|
+
increment(key: string, by?: number): Promise<number>;
|
|
88
|
+
decrement(key: string, by?: number): Promise<number>;
|
|
89
|
+
forever(key: string, value: unknown): Promise<boolean>;
|
|
90
|
+
pull<T = unknown>(key: string, defaultValue?: T): Promise<T | undefined>;
|
|
91
|
+
forget(key: string): Promise<boolean>;
|
|
92
|
+
flush(): Promise<boolean>;
|
|
93
|
+
remember<T>(key: string, ttlSeconds: number, callback: () => T | Promise<T>): Promise<T>;
|
|
94
|
+
rememberForever<T>(key: string, callback: () => T | Promise<T>): Promise<T>;
|
|
95
|
+
lock(name: string, seconds?: number, owner?: string): Lock;
|
|
96
|
+
tags(_names: string | string[]): CacheRepository;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Backs both the `memory` and `array` drivers: `array` is just a MemoryStore with no `maxItems` bound.
|
|
101
|
+
* A bounded store evicts least-recently-used entries, and that includes held locks (GenericLock keys).
|
|
102
|
+
*/
|
|
103
|
+
declare class MemoryStore implements Store {
|
|
104
|
+
private readonly keyPrefix;
|
|
105
|
+
private readonly maxItems?;
|
|
106
|
+
private readonly entries;
|
|
107
|
+
constructor(keyPrefix?: string, maxItems?: number | undefined);
|
|
108
|
+
private k;
|
|
109
|
+
/** Reads and, on a hit, re-inserts the entry so Map iteration order tracks recency (a simple LRU). */
|
|
110
|
+
private read;
|
|
111
|
+
private write;
|
|
112
|
+
get(key: string): Promise<unknown>;
|
|
113
|
+
many(keys: string[]): Promise<Record<string, unknown>>;
|
|
114
|
+
put(key: string, value: unknown, seconds: number): Promise<boolean>;
|
|
115
|
+
putForever(key: string, value: unknown): Promise<boolean>;
|
|
116
|
+
add(key: string, value: unknown, seconds?: number): Promise<boolean>;
|
|
117
|
+
increment(key: string, by: number): Promise<number>;
|
|
118
|
+
decrement(key: string, by: number): Promise<number>;
|
|
119
|
+
forget(key: string): Promise<boolean>;
|
|
120
|
+
flush(): Promise<boolean>;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Store impl at `storage/framework/cache/data`: hashed paths, atomic writes (temp file + rename). Reads never
|
|
125
|
+
* delete anything: an expired or corrupt file is simply a miss, and is replaced by the next write.
|
|
126
|
+
*/
|
|
127
|
+
declare class FileStore implements Store {
|
|
128
|
+
private readonly directory;
|
|
129
|
+
private readonly keyPrefix;
|
|
130
|
+
constructor(directory: string, keyPrefix?: string);
|
|
131
|
+
private path;
|
|
132
|
+
private tempPath;
|
|
133
|
+
private encode;
|
|
134
|
+
/** Undefined for a missing or corrupt file; the payload (possibly expired) otherwise. */
|
|
135
|
+
private readPayload;
|
|
136
|
+
private writeTemp;
|
|
137
|
+
private atomicWrite;
|
|
138
|
+
get(key: string): Promise<unknown>;
|
|
139
|
+
many(keys: string[]): Promise<Record<string, unknown>>;
|
|
140
|
+
put(key: string, value: unknown, seconds: number): Promise<boolean>;
|
|
141
|
+
putForever(key: string, value: unknown): Promise<boolean>;
|
|
142
|
+
/**
|
|
143
|
+
* Exclusive create is the atomicity primitive, but the exclusive step is a hard link, not opening `path`
|
|
144
|
+
* directly with `wx`: the full payload is written to a temp file first, then `link()`'d into place. `link()`
|
|
145
|
+
* is atomic and fails `EEXIST` if the destination already exists, so no concurrent reader can ever observe a
|
|
146
|
+
* half-written file at `path` — unlike creating `path` itself with `wx` and writing to it afterwards, which
|
|
147
|
+
* leaves a window (between file creation and the write completing) where a concurrent `get()`/`add()` can read
|
|
148
|
+
* an empty or truncated file and throw a JSON parse error instead of losing the race cleanly.
|
|
149
|
+
*
|
|
150
|
+
* If the key holds an expired or corrupt entry, the takeover happens under a per-key mutex (see
|
|
151
|
+
* takeOverExpired), so two callers can never both replace it.
|
|
152
|
+
*/
|
|
153
|
+
add(key: string, value: unknown, seconds?: number): Promise<boolean>;
|
|
154
|
+
private linkExclusive;
|
|
155
|
+
/**
|
|
156
|
+
* Replaces an expired or corrupt entry, holding `path + '.lock'` (created with the same link() trick) so only
|
|
157
|
+
* one add() at a time can take it over. A caller that finds the mutex held loses without waiting: the holder
|
|
158
|
+
* is replacing the entry right now, so at that moment the key is taken either way. Inside the mutex the entry
|
|
159
|
+
* is re-read (it may have been replaced by a put() meanwhile), then removed and our file linked in: if anything
|
|
160
|
+
* else creates the key in between (a put(), or an add() after a forget()), the link fails and we lose cleanly.
|
|
161
|
+
*/
|
|
162
|
+
private takeOverExpired;
|
|
163
|
+
/** Returns our token once the mutex is held, or undefined if another live holder has it. */
|
|
164
|
+
private acquireMutex;
|
|
165
|
+
/** Only removes the mutex if it is still ours (a stalled holder's mutex may have been cleared as stale). */
|
|
166
|
+
private releaseMutex;
|
|
167
|
+
increment(key: string, by: number): Promise<number>;
|
|
168
|
+
decrement(key: string, by: number): Promise<number>;
|
|
169
|
+
forget(key: string): Promise<boolean>;
|
|
170
|
+
/** Clears the whole directory, regardless of prefix — matches Laravel's FileStore::flush(). */
|
|
171
|
+
flush(): Promise<boolean>;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/** Store impl over the `cache` table, resolved through DatabaseManager (never imports @orieljs/database). */
|
|
175
|
+
declare class DatabaseStore implements Store {
|
|
176
|
+
private readonly connection;
|
|
177
|
+
private readonly table;
|
|
178
|
+
private readonly keyPrefix;
|
|
179
|
+
constructor(connection: DatabaseConnection, table: string, keyPrefix?: string);
|
|
180
|
+
private k;
|
|
181
|
+
get(key: string): Promise<unknown>;
|
|
182
|
+
many(keys: string[]): Promise<Record<string, unknown>>;
|
|
183
|
+
put(key: string, value: unknown, seconds: number): Promise<boolean>;
|
|
184
|
+
putForever(key: string, value: unknown): Promise<boolean>;
|
|
185
|
+
private write;
|
|
186
|
+
/**
|
|
187
|
+
* Laravel's DatabaseStore::add(): an insert that skips a taken key, and then a conditional update that only takes
|
|
188
|
+
* over an expired row (see insertOrTakeOver). Nothing fails on a taken key, so a caller's transaction stays usable.
|
|
189
|
+
*/
|
|
190
|
+
add(key: string, value: unknown, seconds?: number): Promise<boolean>;
|
|
191
|
+
increment(key: string, by: number, attempt?: number): Promise<number>;
|
|
192
|
+
decrement(key: string, by: number): Promise<number>;
|
|
193
|
+
forget(key: string): Promise<boolean>;
|
|
194
|
+
flush(): Promise<boolean>;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Backs a Lock with any Store whose add() is atomic (memory, array, file). Shares the store's key space with
|
|
199
|
+
* regular cache entries, exactly like Laravel's CacheLock: `Cache::lock('x')` and `Cache::put('x', ...)` name the
|
|
200
|
+
* same slot on purpose.
|
|
201
|
+
*/
|
|
202
|
+
declare class GenericLock implements Lock {
|
|
203
|
+
private readonly store;
|
|
204
|
+
private readonly name;
|
|
205
|
+
private readonly seconds;
|
|
206
|
+
private readonly pollMs;
|
|
207
|
+
private readonly ownerValue;
|
|
208
|
+
constructor(store: Store, name: string, seconds: number | undefined, owner?: string, pollMs?: number);
|
|
209
|
+
owner(): string;
|
|
210
|
+
get<T = boolean>(callback?: () => T | Promise<T>): Promise<T | false>;
|
|
211
|
+
block<T = boolean>(seconds: number, callback?: () => T | Promise<T>): Promise<T | true>;
|
|
212
|
+
release(): Promise<boolean>;
|
|
213
|
+
forceRelease(): Promise<void>;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Locks use their own `cache_locks` table (not `cache`), like Laravel's DatabaseLock: a `value` column with
|
|
218
|
+
* arbitrary serialized data would make comparing owners awkward, so locks get dedicated `owner`/`expiration`
|
|
219
|
+
* columns instead.
|
|
220
|
+
*/
|
|
221
|
+
declare class DatabaseLock implements Lock {
|
|
222
|
+
private readonly connection;
|
|
223
|
+
private readonly table;
|
|
224
|
+
private readonly name;
|
|
225
|
+
private readonly seconds;
|
|
226
|
+
private readonly pollMs;
|
|
227
|
+
private readonly ownerValue;
|
|
228
|
+
constructor(connection: DatabaseConnection, table: string, name: string, seconds: number | undefined, owner?: string, pollMs?: number);
|
|
229
|
+
owner(): string;
|
|
230
|
+
get<T = boolean>(callback?: () => T | Promise<T>): Promise<T | false>;
|
|
231
|
+
block<T = boolean>(seconds: number, callback?: () => T | Promise<T>): Promise<T | true>;
|
|
232
|
+
release(): Promise<boolean>;
|
|
233
|
+
forceRelease(): Promise<void>;
|
|
234
|
+
/**
|
|
235
|
+
* Laravel's DatabaseLock::acquire(): an insert that skips a taken key, and then a conditional update that only takes
|
|
236
|
+
* over an expired lock (no re-entry for the same owner, like RedisLock); see insertOrTakeOver.
|
|
237
|
+
*/
|
|
238
|
+
private acquire;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* Text for `database/migrations/..._create_cache_table.ts`. Cache does not own migrations — Database does — so
|
|
243
|
+
* this is plain text for the coordinator's Wave-1 C2 skeleton step to copy in, not code Cache compiles against.
|
|
244
|
+
* Mirrors Laravel 11's default cache migration: one file, two tables. `expiration` stays a plain `integer`
|
|
245
|
+
* (int4/int, max 2147483647): DatabaseStore/DatabaseLock's "forever" is a 10-year TTL from now
|
|
246
|
+
* (`FOREVER_SECONDS`), never a fixed epoch sentinel, so it always fits (B8).
|
|
247
|
+
*/
|
|
248
|
+
declare const CACHE_TABLE_MIGRATION = "import { Migration, Schema } from '@orieljs/framework'\n\nexport default class extends Migration {\n async up() {\n await Schema.create('cache', (t) => {\n t.string('key').primary()\n t.text('value')\n t.integer('expiration')\n })\n await Schema.create('cache_locks', (t) => {\n t.string('key').primary()\n t.string('owner')\n t.integer('expiration')\n })\n }\n\n async down() {\n await Schema.dropIfExists('cache_locks')\n await Schema.dropIfExists('cache')\n }\n}\n";
|
|
249
|
+
|
|
250
|
+
interface RedisConfig {
|
|
251
|
+
/** A prebuilt ioredis instance. A string here (Laravel's `'client' => 'phpredis'` style) is ignored. */
|
|
252
|
+
client?: Redis | string;
|
|
253
|
+
url?: string;
|
|
254
|
+
[option: string]: unknown;
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Builds an ioredis client from cache.stores.redis config: a prebuilt client, or a URL and/or raw ioredis
|
|
258
|
+
* options. With a URL, the remaining options (db, password, lazyConnect...) are still passed through.
|
|
259
|
+
*/
|
|
260
|
+
declare function makeRedisClient(config: RedisConfig): Redis;
|
|
261
|
+
/** Shared low-level redis primitives, parameterized only by the fully-computed key. No prefixing here on purpose:
|
|
262
|
+
* RedisStore and RedisTaggedStore each compute their own keys and never rely on ioredis's `keyPrefix` client
|
|
263
|
+
* option (which doesn't rewrite SCAN's MATCH pattern, making prefixed flush()/tag-namespace lookups unreliable). */
|
|
264
|
+
declare abstract class RedisPrimitives {
|
|
265
|
+
protected readonly redis: Redis;
|
|
266
|
+
protected constructor(redis: Redis);
|
|
267
|
+
protected rawGet(key: string): Promise<unknown>;
|
|
268
|
+
protected rawMany(keys: string[]): Promise<Record<string, unknown>>;
|
|
269
|
+
protected rawPut(key: string, value: unknown, ms?: number): Promise<boolean>;
|
|
270
|
+
protected rawAdd(key: string, value: unknown, ms?: number): Promise<boolean>;
|
|
271
|
+
protected rawIncrement(key: string, by: number): Promise<number>;
|
|
272
|
+
protected rawForget(key: string): Promise<boolean>;
|
|
273
|
+
}
|
|
274
|
+
declare class RedisStore extends RedisPrimitives implements Store {
|
|
275
|
+
private readonly keyPrefix;
|
|
276
|
+
constructor(redis: Redis, keyPrefix?: string);
|
|
277
|
+
private k;
|
|
278
|
+
getPrefix(): string;
|
|
279
|
+
get(key: string): Promise<unknown>;
|
|
280
|
+
many(keys: string[]): Promise<Record<string, unknown>>;
|
|
281
|
+
put(key: string, value: unknown, seconds: number): Promise<boolean>;
|
|
282
|
+
putForever(key: string, value: unknown): Promise<boolean>;
|
|
283
|
+
add(key: string, value: unknown, seconds?: number): Promise<boolean>;
|
|
284
|
+
increment(key: string, by: number): Promise<number>;
|
|
285
|
+
decrement(key: string, by: number): Promise<number>;
|
|
286
|
+
forget(key: string): Promise<boolean>;
|
|
287
|
+
flush(): Promise<boolean>;
|
|
288
|
+
tags(names: string[]): RedisTaggedStore;
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* A namespaced view of the same redis database. Every tag has a version (a random id); the namespace is a hash
|
|
292
|
+
* of the sorted tag=version pairs. flush() bumps every tag's version, orphaning previously-namespaced entries
|
|
293
|
+
* (they aren't deleted — they expire on their own TTL) — this is Laravel's actual TagSet::reset() behaviour.
|
|
294
|
+
*/
|
|
295
|
+
declare class RedisTaggedStore extends RedisPrimitives implements Store {
|
|
296
|
+
private readonly keyPrefix;
|
|
297
|
+
private readonly tagNames;
|
|
298
|
+
constructor(redis: Redis, keyPrefix: string, tagNames: string[]);
|
|
299
|
+
private tagVersion;
|
|
300
|
+
private namespace;
|
|
301
|
+
private k;
|
|
302
|
+
get(key: string): Promise<unknown>;
|
|
303
|
+
many(keys: string[]): Promise<Record<string, unknown>>;
|
|
304
|
+
put(key: string, value: unknown, seconds: number): Promise<boolean>;
|
|
305
|
+
putForever(key: string, value: unknown): Promise<boolean>;
|
|
306
|
+
add(key: string, value: unknown, seconds?: number): Promise<boolean>;
|
|
307
|
+
increment(key: string, by: number): Promise<number>;
|
|
308
|
+
decrement(key: string, by: number): Promise<number>;
|
|
309
|
+
forget(key: string): Promise<boolean>;
|
|
310
|
+
flush(): Promise<boolean>;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
/** SET key value [PX ms] NX to acquire; a Lua script to release only if we still own it (compare-and-delete). */
|
|
314
|
+
declare class RedisLock implements Lock {
|
|
315
|
+
private readonly redis;
|
|
316
|
+
private readonly name;
|
|
317
|
+
private readonly seconds;
|
|
318
|
+
private readonly pollMs;
|
|
319
|
+
private readonly ownerValue;
|
|
320
|
+
constructor(redis: Redis, name: string, seconds: number | undefined, owner?: string, pollMs?: number);
|
|
321
|
+
owner(): string;
|
|
322
|
+
get<T = boolean>(callback?: () => T | Promise<T>): Promise<T | false>;
|
|
323
|
+
block<T = boolean>(seconds: number, callback?: () => T | Promise<T>): Promise<T | true>;
|
|
324
|
+
release(): Promise<boolean>;
|
|
325
|
+
forceRelease(): Promise<void>;
|
|
326
|
+
private acquire;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
/** The only Repository subclass: the only store where tags() doesn't throw. */
|
|
330
|
+
declare class RedisRepository extends Repository {
|
|
331
|
+
private readonly redisStore;
|
|
332
|
+
private readonly redis;
|
|
333
|
+
constructor(redisStore: RedisStore, redis: Redis);
|
|
334
|
+
tags(names: string | string[]): CacheRepository;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
type StoreConfig = Record<string, unknown>;
|
|
338
|
+
type Driver = (config: StoreConfig) => CacheRepository;
|
|
339
|
+
/**
|
|
340
|
+
* Resolves the ioredis config for the `redis` cache driver, as a pure function so the fallback logic is testable
|
|
341
|
+
* without a real redis connection. An inline `url` or client instance on `cache.stores.redis` wins and is passed straight
|
|
342
|
+
* through; otherwise this falls back to `database.redis.<connection ?? 'default'>` (U3, Laravel's own
|
|
343
|
+
* convention) — Session and Queue's redis connections resolve the exact same way, so one `database.redis`
|
|
344
|
+
* config block covers every component that needs redis.
|
|
345
|
+
*/
|
|
346
|
+
declare function resolveRedisConfig(cfg: StoreConfig, lookupDatabaseRedis: (connectionName: string) => StoreConfig): StoreConfig;
|
|
347
|
+
declare class CacheManager implements CacheManager$1 {
|
|
348
|
+
private readonly container;
|
|
349
|
+
private readonly stores;
|
|
350
|
+
private readonly drivers;
|
|
351
|
+
constructor(container: Container);
|
|
352
|
+
private str;
|
|
353
|
+
private cacheConfig;
|
|
354
|
+
private buildDatabaseStore;
|
|
355
|
+
private buildRedisStore;
|
|
356
|
+
store(name?: string): CacheRepository;
|
|
357
|
+
extend(driver: string, factory: Driver): void;
|
|
358
|
+
get<T = unknown>(key: string, defaultValue?: T | (() => T)): Promise<T | undefined>;
|
|
359
|
+
many<T = unknown>(keys: string[]): Promise<Record<string, T | undefined>>;
|
|
360
|
+
has(key: string): Promise<boolean>;
|
|
361
|
+
missing(key: string): Promise<boolean>;
|
|
362
|
+
put(key: string, value: unknown, ttlSeconds?: number): Promise<boolean>;
|
|
363
|
+
add(key: string, value: unknown, ttlSeconds?: number): Promise<boolean>;
|
|
364
|
+
increment(key: string, by?: number): Promise<number>;
|
|
365
|
+
decrement(key: string, by?: number): Promise<number>;
|
|
366
|
+
forever(key: string, value: unknown): Promise<boolean>;
|
|
367
|
+
pull<T = unknown>(key: string, defaultValue?: T): Promise<T | undefined>;
|
|
368
|
+
forget(key: string): Promise<boolean>;
|
|
369
|
+
flush(): Promise<boolean>;
|
|
370
|
+
remember<T>(key: string, ttlSeconds: number, callback: () => T | Promise<T>): Promise<T>;
|
|
371
|
+
rememberForever<T>(key: string, callback: () => T | Promise<T>): Promise<T>;
|
|
372
|
+
lock(name: string, seconds?: number, owner?: string): _orieljs_contracts.Lock;
|
|
373
|
+
tags(names: string | string[]): CacheRepository;
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
declare const Cache: _orieljs_support.Facade<CacheManager$1, object>;
|
|
377
|
+
declare function cache(): CacheManager$1;
|
|
378
|
+
declare function cache(key: string): Promise<unknown>;
|
|
379
|
+
declare function cache(values: Record<string, unknown>, ttlSeconds?: number): Promise<boolean>;
|
|
380
|
+
|
|
381
|
+
declare class CacheServiceProvider extends ServiceProvider {
|
|
382
|
+
register(): void;
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
export { CACHE_TABLE_MIGRATION, Cache, CacheManager, CacheServiceProvider, DatabaseLock, DatabaseStore, FileStore, GenericLock, InvalidCacheConfigError, type LockFactory, LockTimeoutError, MemoryStore, RedisLock, RedisRepository, RedisStore, RedisTaggedStore, Repository, type Store, TagsNotSupportedError, UnknownCacheDriverError, UnknownCacheStoreError, cache, defaultLockFactory, deserialize, makeRedisClient, resolveRedisConfig, roundTrip, serialize };
|