-
Notifications
You must be signed in to change notification settings - Fork 180
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cache-manager - adding disconnect to cache (#899)
* cache-manager - adding disconnect() * adding missed coverage * adding in information on when to disconnect --------- Co-authored-by: Jared Wray <[email protected]>
- Loading branch information
Showing
5 changed files
with
110 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { | ||
describe, expect, test, vi, | ||
} from 'vitest'; | ||
import {Keyv} from 'keyv'; | ||
import KeyvRedis from '@keyv/redis'; | ||
import {CacheableMemory} from 'cacheable'; | ||
import {createCache} from '../src/index.js'; | ||
|
||
describe('disconnect', () => { | ||
test('disconnect from multiple stores', async () => { | ||
const cacheableKeyvStore = new Keyv({ | ||
store: new CacheableMemory({ttl: 60_000, lruSize: 5000}), | ||
}); | ||
const redisKeyvStore = new Keyv({ | ||
store: new KeyvRedis('redis://localhost:6379'), | ||
}); | ||
// Multiple stores | ||
const cache = createCache({ | ||
stores: [ | ||
cacheableKeyvStore, | ||
redisKeyvStore, | ||
], | ||
}); | ||
|
||
const cacheableDisconnectSpy = vi.spyOn(cacheableKeyvStore, 'disconnect'); | ||
const redisDisconnectSpy = vi.spyOn(redisKeyvStore, 'disconnect'); | ||
await cache.disconnect(); | ||
|
||
expect(cacheableDisconnectSpy).toBeCalled(); | ||
expect(redisDisconnectSpy).toBeCalled(); | ||
}); | ||
test('error', async () => { | ||
const keyv = new Keyv(); | ||
const cache = createCache({ | ||
stores: [ | ||
keyv, | ||
], | ||
}); | ||
const error = new Error('disconnect error'); | ||
keyv.disconnect = () => { | ||
throw error; | ||
}; | ||
|
||
await expect(cache.disconnect()).rejects.toThrowError(error); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters