@accounter/server
Version:
The test suite is split into three Vitest projects for efficiency and isolation:
38 lines (31 loc) • 973 B
text/typescript
import { Injectable, Scope } from 'graphql-modules';
import { sql } from '@pgtyped/runtime';
import { getCacheInstance } from '../../../shared/helpers/index.js';
import { DBProvider } from '../../app-providers/db.provider.js';
import type { IGetRecoveryDataQuery, IGetRecoveryDataResult } from '../types.js';
const getRecoveryData = sql<IGetRecoveryDataQuery>`
SELECT *
FROM accounter_schema.recovery;`;
({
scope: Scope.Singleton,
global: true,
})
export class RecoveryProvider {
cache = getCacheInstance({
stdTTL: 60 * 5,
});
constructor(private dbProvider: DBProvider) {}
public getRecoveryData() {
const cached = this.cache.get<IGetRecoveryDataResult[]>('recovery');
if (cached) {
return Promise.resolve(cached);
}
return getRecoveryData.run(undefined, this.dbProvider).then(res => {
this.cache.set('recovery', res);
return res;
});
}
public clearCache() {
this.cache.clear();
}
}