-
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.
* cache() and cacheLatest() working * Move clients to standalone files * Move to closure style to properly export required functions * Comments * Adds RedisClient * Simplify logic to remove separate init() function * Refactor for more generic client usage, no more init() * Adds redis package * Moves cache clients to devDependencies * Simplify memcached options on init * Use logger for messages * Server connection string must be included * Adds docs on service caching * Add timeout for cache calls * Adds setup command for cache * Updates templates with new timeout option * Updates docs for new createCache() client * Comment * Move errors to separate file * Allow renaming of id/updatedAt fields, catch error if model has no id/updatedAt, catch if no records in cacheLatest * Allow adding a global prefix to cache key * Adds docs for global prefix, options, array key syntax * Move formatting of cache key to a standalone function, allow cache key as an array * cacheLatest -> cacheFindMany, exports some additional functions, updates types * Start of tests * Adds InMemoryClient for cache testing * Create base cache client class to extend from, rename clients for consistency * Adds cache tests * Doc updates * --rebuild-fixture * Update templates for cacheFindMany * yarn constraints --fix * Updates lock file with constraints fix * Refactor to use TS abstract class * Types in template * Fixes `setup cache` CLI command * Export client defaults as named exports * InMemoryCache is a default export now * Fix link * Doc updates * More doc updates * Adds docs for `setup cache` command * Adds some complex types to inputs and results Thanks @dac09! * Adds test for no records found * Adds spys to check on client calls * Fix some type issues Fix bugs in tests * Remove specific types for cache and cacheFindMany result * Handle redis disconnect * Pass logger to RedisClient * Use logger instead of console in Memcached config * Adds reconnect() function * Attempt reconnect on timeout error * Adds test for reconnect() * Remove commented mock code * Update docs/docs/cli-commands.md Co-authored-by: Daniel Choudhury <[email protected]> * Update packages/api/src/cache/clients/BaseClient.ts Co-authored-by: Daniel Choudhury <[email protected]> * Update packages/cli/src/commands/setup/cache/cache.js Co-authored-by: Daniel Choudhury <[email protected]> * Update docs/docs/services.md Co-authored-by: Daniel Choudhury <[email protected]> * Moves addPackagesTask to shared location * Add memjs/redis package based on client choice during setup * Fix type issue in BaseClient * Refactor to use async imports Introduce connect/disconnect * fix: reconnect -> disconnect tests * Adds testing helpers for contents of InMemoryCache * Updates cache templates to include testing check, moves host URL to ENV var * Move cache server connection string to .env * Move adding env var code to shared helper * Export client for testing * Fix merge conflicts * Use addEnvVarTask from cli helpers * Use listr2 instead * WIP(testing): Add custom matcher to check cached values * Add contents and clear to InMemoryCache * Unused imports in deploy helpers * Fix bugs in the cli helper * Add partialMatch helper * Updates `toHaveCached()` to accept an optional argument Can include the key you expect the value to have so that you can verify both * Update custom matcher, comments * Support multiple values in partialMatch array | Disable parse(stringfy()) * Provide options to toHaveCached() * fix: Check string values after serializing | update types * docs: Update testing docs * docs: small update * fix: Remove matcher options Update docs on strict matching * Update docs/docs/testing.md * fix(cli): Fix Listr import in cache setup cli * Update docs/docs/services.md Co-authored-by: Dominic Saadi <[email protected]> * Update docs/docs/services.md Co-authored-by: Dominic Saadi <[email protected]> * Apply suggestions from code review Co-authored-by: Dominic Saadi <[email protected]> Co-authored-by: Rob Cameron <[email protected]> * Apply suggestions from code review Co-authored-by: Dominic Saadi <[email protected]> * Update docs/docs/services.md Co-authored-by: Dominic Saadi <[email protected]> * Code example changes Co-authored-by: Daniel Choudhury <[email protected]> Co-authored-by: Dominic Saadi <[email protected]>
- Loading branch information
1 parent
0bb0f8c
commit 34125a5
Showing
31 changed files
with
1,677 additions
and
106 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
Large diffs are not rendered by default.
Oops, something went wrong.
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,2 @@ | ||
/* eslint-env es6, commonjs */ | ||
module.exports = require('../dist/cache/index') |
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,4 @@ | ||
{ | ||
"main": "./index.js", | ||
"types": "../dist/cache/index.d.ts" | ||
} |
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,30 @@ | ||
import InMemoryClient from '../clients/InMemoryClient' | ||
import { createCache } from '../index' | ||
|
||
describe('cache', () => { | ||
it('adds a missing key to the cache', async () => { | ||
const client = new InMemoryClient() | ||
const { cache } = createCache(client) | ||
|
||
const result = await cache('test', () => { | ||
return { foo: 'bar' } | ||
}) | ||
|
||
expect(result).toEqual({ foo: 'bar' }) | ||
expect(client.storage.test.value).toEqual(JSON.stringify({ foo: 'bar' })) | ||
}) | ||
|
||
it('finds an existing key in the cache', async () => { | ||
const client = new InMemoryClient({ | ||
test: { expires: 1977175194415, value: '{"foo":"bar"}' }, | ||
}) | ||
const { cache } = createCache(client) | ||
|
||
const result = await cache('test', () => { | ||
return { bar: 'baz' } | ||
}) | ||
|
||
// returns existing cached value, not the one that was just set | ||
expect(result).toEqual({ foo: 'bar' }) | ||
}) | ||
}) |
Oops, something went wrong.