Skip to content

Commit 847b3a0

Browse files
committed
Improve item.add cache invalidation logic so that it doesn't purge the entire cache
1 parent a69072b commit 847b3a0

File tree

1 file changed

+16
-3
lines changed
  • src/puter-js/src/modules/FileSystem

1 file changed

+16
-3
lines changed

src/puter-js/src/modules/FileSystem/index.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,22 @@ export class PuterJSFileSystemModule extends AdvancedBase {
153153
});
154154

155155
this.socket.on('item.added', (item) => {
156-
// check original_client_socket_id and if it matches this.socket.id, don't invalidate cache
157-
puter._cache.flushall();
158-
console.log('Flushed cache for item.added');
156+
// delete item from cache
157+
puter._cache.del('item:' + item.path);
158+
// delete readdir from cache
159+
puter._cache.del('readdir:' + item.path);
160+
// delete descendant items from cache
161+
const descendant_items = puter._cache.keys('item:' + item.path + '/*');
162+
for(const descendant of descendant_items){
163+
puter._cache.del(descendant);
164+
}
165+
// delete descendant readdirs from cache
166+
const descendant_readdirs = puter._cache.keys('readdir:' + item.path + '/*');
167+
for(const descendant of descendant_readdirs){
168+
puter._cache.del(descendant);
169+
}
170+
// delete parent readdir from cache
171+
puter._cache.del('readdir:' + path.dirname(item.path));
159172
});
160173

161174
this.socket.on('item.updated', (item) => {

0 commit comments

Comments
 (0)