diff --git a/src/puter-js/src/modules/FileSystem/index.js b/src/puter-js/src/modules/FileSystem/index.js index 998f8887c..88ff9a386 100644 --- a/src/puter-js/src/modules/FileSystem/index.js +++ b/src/puter-js/src/modules/FileSystem/index.js @@ -1,5 +1,6 @@ import io from '../../lib/socket.io/socket.io.esm.min.js'; import * as utils from '../../lib/utils.js'; +import path from '../../lib/path.js'; // Constants // @@ -122,9 +123,27 @@ 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 invalidate cache - puter._cache.flushall(); - console.log('Flushed cache for item.renamed'); + // delete old item from cache + puter._cache.del('item:' + item.old_path); + // if a directory + if(item.is_dir){ + // delete readdir + puter._cache.del('readdir:' + item.old_path); + // descendants items + const descendants = puter._cache.keys('item:' + item.old_path + '/*'); + for(const descendant of descendants){ + console.log('Deleting cache for:', descendant); + puter._cache.del(descendant); + } + // descendants readdirs + const descendants_readdir = puter._cache.keys('readdir:' + item.old_path + '/*'); + for(const descendant of descendants_readdir){ + console.log('Deleting cache for:', descendant); + puter._cache.del(descendant); + } + } + // parent readdir + puter._cache.del('readdir:' + path.dirname(item.old_path)); }); this.socket.on('item.removed', (item) => { diff --git a/src/puter-js/src/modules/FileSystem/operations/readdir.js b/src/puter-js/src/modules/FileSystem/operations/readdir.js index 4a0ee9b81..44c3490c7 100644 --- a/src/puter-js/src/modules/FileSystem/operations/readdir.js +++ b/src/puter-js/src/modules/FileSystem/operations/readdir.js @@ -66,12 +66,12 @@ const readdir = async function (...args) { if(resultSize <= MAX_CACHE_SIZE){ // UPSERT the cache - await puter._cache.set(cacheKey, result); + puter._cache.set(cacheKey, result); } // set each individual item's cache for(const item of result){ - await puter._cache.set('item:' + item.path, item); + puter._cache.set('item:' + item.path, item); } resolve(result); diff --git a/src/puter-js/src/modules/FileSystem/operations/stat.js b/src/puter-js/src/modules/FileSystem/operations/stat.js index 0102ec147..2955dd2d8 100644 --- a/src/puter-js/src/modules/FileSystem/operations/stat.js +++ b/src/puter-js/src/modules/FileSystem/operations/stat.js @@ -39,8 +39,6 @@ const stat = async function (...args) { let cacheKey; if(options.path){ cacheKey = 'item:' + options.path; - }else if(options.uid){ - cacheKey = 'item:' + options.uid; } if(options.consistency === 'eventual' && !options.returnSubdomains && !options.returnPermissions && !options.returnVersions && !options.returnSize){ @@ -65,8 +63,7 @@ const stat = async function (...args) { if(resultSize <= MAX_CACHE_SIZE){ // UPSERT the cache - await puter._cache.set('item:' + result.path, result); - await puter._cache.set('item:' + result.uid, result); + puter._cache.set(cacheKey, result); } resolve(result);