Skip to content

Commit

Permalink
feat(inji-411): Remove caching for vc files (mosip#995)
Browse files Browse the repository at this point in the history
Signed-off-by: Tilak Puli <[email protected]>
  • Loading branch information
tilak-puli authored and srikanth716 committed Nov 23, 2023
1 parent cc16034 commit 108b3e7
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 43 deletions.
15 changes: 1 addition & 14 deletions machines/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import {
isHardwareKeystoreExists,
} from '../shared/cryptoutil/cryptoUtil';
import {VCMetadata} from '../shared/VCMetadata';
import FileStorage, {getFilePath} from '../shared/fileStorage';

export const keyinvalidatedString =
'Key Invalidated due to biometric enrollment';
Expand Down Expand Up @@ -173,7 +172,7 @@ export const storeMachine =
},
},
ready: {
entry: ['notifyParent', 'cacheVCFilesData'],
entry: 'notifyParent',
invoke: {
src: 'store',
id: '_store',
Expand Down Expand Up @@ -259,18 +258,6 @@ export const storeMachine =
setEncryptionKey: model.assign({
encryptionKey: (_, event) => event.key,
}),

cacheVCFilesData: context => {
getItem(MY_VCS_STORE_KEY, [], context.encryptionKey).then(vcList => {
if (vcList) {
vcList?.forEach((vcMetadataStr: string) => {
const vcKey =
VCMetadata.fromVcMetadataString(vcMetadataStr).getVcKey();
FileStorage.readAndCacheFile(getFilePath(vcKey));
});
}
});
},
},

services: {
Expand Down
28 changes: 0 additions & 28 deletions shared/fileStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,34 +24,6 @@ class FileStorage {
return await readFile(path, 'utf8');
}

async readFromCacheFile(path: string) {
if (this.cache[path]?.data) {
const count = this.cache[path]?.count ?? 0;
const data = this.cache[path]?.data;

if (count != undefined && count <= 1) {
this.cache[path] = {};
} else {
this.cache[path].count = count - 1;
}

return data;
}

return this.readFile(path);
}

async readAndCacheFile(path: string, useCount: number = 1) {
const data = await this.readFile(path);

this.cache[path] = {
data,
count: useCount,
};

return data;
}

async writeFile(path: string, data: string) {
return await writeFile(path, data, 'utf8');
}
Expand Down
2 changes: 1 addition & 1 deletion shared/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ class Storage {
}

private static async readVCFromFile(key: string) {
return await FileStorage.readFromCacheFile(getFilePath(key));
return await FileStorage.readFile(getFilePath(key));
}

private static async storeVC(key: string, data: string) {
Expand Down

0 comments on commit 108b3e7

Please sign in to comment.