File tree Expand file tree Collapse file tree 1 file changed +12
-0
lines changed
packages/core/src/shared/utilities Expand file tree Collapse file tree 1 file changed +12
-0
lines changed Original file line number Diff line number Diff line change @@ -26,6 +26,17 @@ function now() {
2626 return globals . clock . Date . now ( )
2727}
2828
29+ /**
30+ * args:
31+ * key: global state key, which is used for globals.globalState#update, #tryGet etc.
32+ * expirationInMilli: cache expiration time in milli seconds
33+ * defaultValue: default value for the cache if the cache doesn't pre-exist in users' FS
34+ * waitUntilOption: waitUntil option for acquire lock
35+ *
36+ * methods:
37+ * resourceProvider(): implementation needs to implement this method to obtain the latest resource either via network calls or FS read
38+ * getResource(): obtain the resource from cache or pull the latest from the service if the cache either expires or doesn't exist
39+ */
2940export abstract class CachedResource < V > {
3041 constructor (
3142 private readonly key : globalKey ,
@@ -100,6 +111,7 @@ export abstract class CachedResource<V> {
100111 return lock
101112 }
102113
114+ // TODO: releaseLock and updateCache do similar things, how to improve
103115 async releaseLock ( ) {
104116 await globals . globalState . update ( this . key , {
105117 ...this . readCacheOrDefault ( ) ,
You can’t perform that action at this time.
0 commit comments