mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
refactor: use NodeCache arg in cacheable signal store
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
import { randomBytes } from 'crypto'
|
import { randomBytes } from 'crypto'
|
||||||
import NodeCache from 'node-cache'
|
import NodeCache from 'node-cache'
|
||||||
import type { Logger } from 'pino'
|
import type { Logger } from 'pino'
|
||||||
|
import { DEFAULT_CACHE_TTLS } from '../Defaults'
|
||||||
import type { AuthenticationCreds, SignalDataSet, SignalDataTypeMap, SignalKeyStore, SignalKeyStoreWithTransaction, TransactionCapabilityOptions } from '../Types'
|
import type { AuthenticationCreds, SignalDataSet, SignalDataTypeMap, SignalKeyStore, SignalKeyStoreWithTransaction, TransactionCapabilityOptions } from '../Types'
|
||||||
import { Curve, signedKeyPair } from './crypto'
|
import { Curve, signedKeyPair } from './crypto'
|
||||||
import { delay, generateRegistrationId } from './generics'
|
import { delay, generateRegistrationId } from './generics'
|
||||||
@@ -9,15 +10,15 @@ import { delay, generateRegistrationId } from './generics'
|
|||||||
* Adds caching capability to a SignalKeyStore
|
* Adds caching capability to a SignalKeyStore
|
||||||
* @param store the store to add caching to
|
* @param store the store to add caching to
|
||||||
* @param logger to log trace events
|
* @param logger to log trace events
|
||||||
* @param opts NodeCache options
|
* @param _cache NodeCache to use
|
||||||
*/
|
*/
|
||||||
export function makeCacheableSignalKeyStore(
|
export function makeCacheableSignalKeyStore(
|
||||||
store: SignalKeyStore,
|
store: SignalKeyStore,
|
||||||
logger: Logger,
|
logger: Logger,
|
||||||
opts?: NodeCache.Options
|
_cache?: NodeCache
|
||||||
): SignalKeyStore {
|
): SignalKeyStore {
|
||||||
const cache = new NodeCache({
|
const cache = _cache || new NodeCache({
|
||||||
...opts || { },
|
stdTTL: DEFAULT_CACHE_TTLS.SIGNAL_STORE, // 5 minutes
|
||||||
useClones: false,
|
useClones: false,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user