-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds ability to delete a cache entry (#7016)
* Adds deleteCacheKey() to exported cache functions * Reorg tests * Remove some comments * Update types, simplify Redis return on del() * Fix double not on promise * Add info block about using a hash of columns in the key
- Loading branch information
Showing
7 changed files
with
139 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import InMemoryClient from '../clients/InMemoryClient' | ||
import { createCache } from '../index' | ||
|
||
describe('deleteCacheKey', () => { | ||
it('deletes a key from the cache', async () => { | ||
const client = new InMemoryClient({ | ||
test: { expires: 1977175194415, value: '{"foo":"bar"}' }, | ||
}) | ||
const { deleteCacheKey } = createCache(client) | ||
|
||
await deleteCacheKey('test') | ||
|
||
expect(client.storage['test']).toEqual(undefined) | ||
}) | ||
|
||
it('returns true if key was deleted', async () => { | ||
const client = new InMemoryClient({ | ||
test: { expires: 1977175194415, value: '{"foo":"bar"}' }, | ||
}) | ||
const { deleteCacheKey } = createCache(client) | ||
|
||
const result = await deleteCacheKey('test') | ||
|
||
expect(result).toEqual(true) | ||
}) | ||
|
||
it('returns false if key did not exist', async () => { | ||
const client = new InMemoryClient({ | ||
test: { expires: 1977175194415, value: '{"foo":"bar"}' }, | ||
}) | ||
const { deleteCacheKey } = createCache(client) | ||
|
||
const result = await deleteCacheKey('foobar') | ||
|
||
expect(result).toEqual(false) | ||
}) | ||
}) |
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
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