Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add LRUCacheOptions #102

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions mqemitter-redis.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ function MQEmitterRedis (opts) {
this._topics = {}

this._cache = new LRUCache({
max: 10000,
ttl: 60 * 1000 // one minute
max: opts.maxLRUCache || 10000, // default: 10k
ttl: opts.ttlLRUCache || 60 * 1000 // default: one minute
})

this.state = new EE()
Expand Down
9 changes: 7 additions & 2 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,15 @@ export interface MQEmitterOptions {
connectionString?: string;
}

export interface LRUCacheOptions {
ttlLRUCache?: number;// Time to live for the LRU cache in milliseconds
maxLRUCache?: number;// Maximum number of items in the LRU cache
}

export type Message = Record<string, any> & { topic: string };

export interface MQEmitterRedis extends MQEmitter {
new (options?: MQEmitterOptions & RedisOptions): MQEmitterRedis;
new (options?: MQEmitterOptions & RedisOptions & LRUCacheOptions): MQEmitterRedis;
current: number;
concurrent: number;
on(
Expand All @@ -31,7 +36,7 @@ export interface MQEmitterRedis extends MQEmitter {
}

declare function MQEmitterRedis(
options?: MQEmitterOptions & RedisOptions
options?: MQEmitterOptions & RedisOptions & LRUCacheOptions
): MQEmitterRedis;

export default MQEmitterRedis;
7 changes: 7 additions & 0 deletions types/index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ expectType<MQEmitterRedis>(
})
);

expectType<MQEmitterRedis>(
mqEmitterRedis({
maxLRUCache: 100,
ttlLRUCache: 10000,
})
);

function listener(message: Message, done: () => void) {}

expectType<MQEmitterRedis>(mqEmitterRedis().on('topic', listener));
Expand Down
Loading