Skip to content

Commit

Permalink
added a localcaching for didDocument
Browse files Browse the repository at this point in the history
  • Loading branch information
Pratap2018 committed Nov 25, 2024
1 parent 605b415 commit 0e24724
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/credential/services/credential.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ import {
} from '../dto/register-credential.dto';
import { getAppVault, getAppMenemonic } from '../../utils/app-vault-service';
import { TxSendModuleService } from 'src/tx-send-module/tx-send-module.service';

import * as NodeCache from 'node-cache';
const myCache = new NodeCache();
@Injectable()
export class CredentialService {
constructor(
Expand Down Expand Up @@ -112,7 +113,16 @@ export class CredentialService {
);
const seed = await this.hidWallet.getSeedFromMnemonic(issuerMnemonic);
const hypersignDid = new HypersignDID();
const { didDocument } = await hypersignDid.resolve({ did: issuerDid });
let didDocument;
if (myCache.has(issuerDid)) {
didDocument = myCache.get(issuerDid);
console.log('Getting from Cache');
} else {
const resp = await hypersignDid.resolve({ did: issuerDid });
didDocument = resp.didDocument;
myCache.set(issuerDid, didDocument);
Logger.log('Setting Cache');
}
const verificationMethod = didDocument.verificationMethod.find(
(vm) => vm.id === verificationMethodId,
);
Expand Down Expand Up @@ -192,6 +202,7 @@ export class CredentialService {
} = await hypersignVC.issue({
credential,
issuerDid,
issuerDidDoc: didDocument,
verificationMethodId,
privateKeyMultibase,
registerCredential: false,
Expand Down

0 comments on commit 0e24724

Please sign in to comment.