mirror of
https://github.com/HeyPuter/puter.git
synced 2026-04-29 03:29:37 -05:00
Remove cache expiry in puter.js
This commit is contained in:
@@ -116,7 +116,7 @@ export class PuterJSFileSystemModule extends AdvancedBase {
|
||||
this.socket.on('cache.updated', (msg) => {
|
||||
// check original_client_socket_id and if it matches this.socket.id, don't post update
|
||||
if (msg.original_client_socket_id !== this.socket.id) {
|
||||
this.postUpdate();
|
||||
this.invalidateCache();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -124,7 +124,7 @@ export class PuterJSFileSystemModule extends AdvancedBase {
|
||||
this.socket.on('item.renamed', (item) => {
|
||||
// check original_client_socket_id and if it matches this.socket.id, don't post update
|
||||
if (item.original_client_socket_id !== this.socket.id) {
|
||||
this.postUpdate();
|
||||
this.invalidateCache();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -218,10 +218,10 @@ export class PuterJSFileSystemModule extends AdvancedBase {
|
||||
* @memberof PuterJSFileSystemModule
|
||||
* @returns {void}
|
||||
*/
|
||||
postUpdate() {
|
||||
invalidateCache() {
|
||||
// Action: Flush local cache
|
||||
puter._cache.flushall();
|
||||
console.log('postUpdate triggered, cache flushed');
|
||||
console.log('invalidateCache triggered, cache flushed');
|
||||
|
||||
// Action: Update last valid time
|
||||
//
|
||||
|
||||
@@ -56,7 +56,7 @@ const copy = function (...args) {
|
||||
dedupe_name: (options.dedupe_name || options.dedupeName),
|
||||
}));
|
||||
|
||||
this.postUpdate();
|
||||
this.invalidateCache();
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -54,7 +54,7 @@ const mkdir = function (...args) {
|
||||
create_missing_parents: (options.recursive || options.createMissingParents) ?? false,
|
||||
}));
|
||||
|
||||
this.postUpdate();
|
||||
this.invalidateCache();
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -66,7 +66,7 @@ const move = function (...args) {
|
||||
original_client_socket_id: options.excludeSocketID,
|
||||
}));
|
||||
|
||||
this.postUpdate();
|
||||
this.invalidateCache();
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -65,17 +65,16 @@ const readdir = async function (...args) {
|
||||
|
||||
// Cache the result if it's not bigger than MAX_CACHE_SIZE
|
||||
const MAX_CACHE_SIZE = 20 * 1024 * 1024;
|
||||
const EXPIRE_TIME = 60 * 60; // 1 hour
|
||||
|
||||
if(resultSize <= MAX_CACHE_SIZE){
|
||||
// UPSERT the cache
|
||||
await puter._cache.set(cacheKey, result, { EX: EXPIRE_TIME });
|
||||
await puter._cache.set(cacheKey, result);
|
||||
}
|
||||
|
||||
// set each individual item's cache
|
||||
for(const item of result){
|
||||
await puter._cache.set('item:' + item.id, item, { EX: EXPIRE_TIME });
|
||||
await puter._cache.set('item:' + item.path, item, { EX: EXPIRE_TIME });
|
||||
await puter._cache.set('item:' + item.id, item);
|
||||
await puter._cache.set('item:' + item.path, item);
|
||||
}
|
||||
|
||||
resolve(result);
|
||||
|
||||
@@ -51,7 +51,7 @@ const rename = function (...args) {
|
||||
|
||||
xhr.send(JSON.stringify(dataToSend));
|
||||
|
||||
this.postUpdate();
|
||||
this.invalidateCache();
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -62,12 +62,11 @@ const stat = async function (...args) {
|
||||
|
||||
// Cache the result if it's not bigger than MAX_CACHE_SIZE
|
||||
const MAX_CACHE_SIZE = 20 * 1024 * 1024;
|
||||
const EXPIRE_TIME = 60 * 60; // 1 hour
|
||||
|
||||
if(resultSize <= MAX_CACHE_SIZE){
|
||||
// UPSERT the cache
|
||||
await puter._cache.set('item:' + result.path, result, { EX: EXPIRE_TIME });
|
||||
await puter._cache.set('item:' + result.uid, result, { EX: EXPIRE_TIME });
|
||||
await puter._cache.set('item:' + result.path, result);
|
||||
await puter._cache.set('item:' + result.uid, result);
|
||||
}
|
||||
|
||||
resolve(result);
|
||||
|
||||
@@ -432,7 +432,7 @@ const upload = async function(items, dirPath, options = {}){
|
||||
// send request
|
||||
xhr.send(fd);
|
||||
|
||||
this.postUpdate();
|
||||
this.invalidateCache();
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -55,7 +55,7 @@ const write = async function (targetPath, data, options = {}) {
|
||||
throw new Error({ code: 'field_invalid', message: 'write() data parameter is an invalid type' });
|
||||
}
|
||||
|
||||
this.postUpdate();
|
||||
this.invalidateCache();
|
||||
|
||||
// perform upload
|
||||
return this.upload(data, parent, options);
|
||||
|
||||
Reference in New Issue
Block a user