Skip to content

Commit

Permalink
feat: made cache object configurable from setupAgent (#23)
Browse files Browse the repository at this point in the history
Signed-off-by: wadeking98 <[email protected]>
  • Loading branch information
wadeking98 authored Sep 18, 2024
1 parent b307567 commit f82ba19
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/helpers/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,8 @@ export type IndyVdrProxyAgent = Agent<ReturnType<typeof getIndyVdrProxyAgentModu
export function setupAgent(options: {
networks: [IndyVdrPoolConfig, ...IndyVdrPoolConfig[]]
logger?: Logger
cache?: { capacity: number; expiryMs: number; path?: string }
}) {
indyVdr.setLedgerTxnCache({
capacity: 1000,
expiry_offset_ms: 1000 * 60 * 60 * 24 * 7,
path: '/tmp/indy-vdr-cache',
})
return new Agent({
config: {
label: 'Indy VDR Proxy',
Expand All @@ -61,11 +57,21 @@ export function setupAgent(options: {
logger: options.logger ?? new ConsoleLogger(LogLevel.debug),
},
dependencies: agentDependencies,
modules: getIndyVdrProxyAgentModules(options.networks),
modules: getIndyVdrProxyAgentModules({ networks: options.networks, cache: options.cache }),
})
}

const getIndyVdrProxyAgentModules = (networks: [IndyVdrPoolConfig, ...IndyVdrPoolConfig[]]) => {
const getIndyVdrProxyAgentModules = (options: {
networks: [IndyVdrPoolConfig, ...IndyVdrPoolConfig[]]
cache?: { capacity: number; expiryMs: number; path?: string }
}) => {
if (options.cache) {
indyVdr.setLedgerTxnCache({
capacity: options.cache.capacity,
expiry_offset_ms: options.cache.expiryMs,
path: options.cache.path,
})
}
return {
askar: new AskarModule({
ariesAskar,
Expand All @@ -77,7 +83,7 @@ const getIndyVdrProxyAgentModules = (networks: [IndyVdrPoolConfig, ...IndyVdrPoo
dids: new DidsModule({ resolvers: [new IndyVdrSovDidResolver()] }),
indyVdr: new IndyVdrModule({
indyVdr,
networks,
networks: options.networks,
}),
} as const
}

0 comments on commit f82ba19

Please sign in to comment.