File tree Expand file tree Collapse file tree 3 files changed +25
-9
lines changed
src/puter-js/src/modules/FileSystem Expand file tree Collapse file tree 3 files changed +25
-9
lines changed Original file line number Diff line number Diff line change 11import io from '../../lib/socket.io/socket.io.esm.min.js' ;
22import * as utils from '../../lib/utils.js' ;
3+ import path from '../../lib/path.js' ;
34
45// Constants
56//
@@ -122,9 +123,27 @@ export class PuterJSFileSystemModule extends AdvancedBase {
122123 // });
123124
124125 this . socket . on ( 'item.renamed' , ( item ) => {
125- // check original_client_socket_id and if it matches this.socket.id, don't invalidate cache
126- puter . _cache . flushall ( ) ;
127- console . log ( 'Flushed cache for item.renamed' ) ;
126+ // delete old item from cache
127+ puter . _cache . del ( 'item:' + item . old_path ) ;
128+ // if a directory
129+ if ( item . is_dir ) {
130+ // delete readdir
131+ puter . _cache . del ( 'readdir:' + item . old_path ) ;
132+ // descendants items
133+ const descendants = puter . _cache . keys ( 'item:' + item . old_path + '/*' ) ;
134+ for ( const descendant of descendants ) {
135+ console . log ( 'Deleting cache for:' , descendant ) ;
136+ puter . _cache . del ( descendant ) ;
137+ }
138+ // descendants readdirs
139+ const descendants_readdir = puter . _cache . keys ( 'readdir:' + item . old_path + '/*' ) ;
140+ for ( const descendant of descendants_readdir ) {
141+ console . log ( 'Deleting cache for:' , descendant ) ;
142+ puter . _cache . del ( descendant ) ;
143+ }
144+ }
145+ // parent readdir
146+ puter . _cache . del ( 'readdir:' + path . dirname ( item . old_path ) ) ;
128147 } ) ;
129148
130149 this . socket . on ( 'item.removed' , ( item ) => {
Original file line number Diff line number Diff line change @@ -66,12 +66,12 @@ const readdir = async function (...args) {
6666
6767 if ( resultSize <= MAX_CACHE_SIZE ) {
6868 // UPSERT the cache
69- await puter . _cache . set ( cacheKey , result ) ;
69+ puter . _cache . set ( cacheKey , result ) ;
7070 }
7171
7272 // set each individual item's cache
7373 for ( const item of result ) {
74- await puter . _cache . set ( 'item:' + item . path , item ) ;
74+ puter . _cache . set ( 'item:' + item . path , item ) ;
7575 }
7676
7777 resolve ( result ) ;
Original file line number Diff line number Diff line change @@ -39,8 +39,6 @@ const stat = async function (...args) {
3939 let cacheKey ;
4040 if ( options . path ) {
4141 cacheKey = 'item:' + options . path ;
42- } else if ( options . uid ) {
43- cacheKey = 'item:' + options . uid ;
4442 }
4543
4644 if ( options . consistency === 'eventual' && ! options . returnSubdomains && ! options . returnPermissions && ! options . returnVersions && ! options . returnSize ) {
@@ -65,8 +63,7 @@ const stat = async function (...args) {
6563
6664 if ( resultSize <= MAX_CACHE_SIZE ) {
6765 // UPSERT the cache
68- await puter . _cache . set ( 'item:' + result . path , result ) ;
69- await puter . _cache . set ( 'item:' + result . uid , result ) ;
66+ puter . _cache . set ( cacheKey , result ) ;
7067 }
7168
7269 resolve ( result ) ;
You can’t perform that action at this time.
0 commit comments