Maybe not THAT transparent.

Signed-off-by: Eric Peterson <ericpeterson@spotify.com>
This commit is contained in:
Eric Peterson
2021-05-10 18:21:27 +02:00
parent 6e2b9a92d6
commit a8c70b3ae4
3 changed files with 9 additions and 34 deletions
+2 -2
View File
@@ -65,9 +65,9 @@ export class BitbucketUrlReader implements UrlReader {
// @public
export interface CacheClient {
delete(key: string): Promise<boolean>;
delete(key: string): Promise<void>;
get(key: string): Promise<JsonValue | undefined>;
set(key: string, value: JsonValue, options?: CacheSetOptions): Promise<boolean>;
set(key: string, value: JsonValue, options?: CacheSetOptions): Promise<void>;
}
// @public
-20
View File
@@ -101,16 +101,6 @@ describe('CacheClient', () => {
return expect(sut.set('someKey', {})).rejects.toEqual(expectedError);
});
it('resolves what underlying client resolves', async () => {
const sut = new DefaultCacheClient({ client });
const expectedResponse = true;
client.set = jest.fn().mockReturnValue(expectedResponse);
const actualResponse = await sut.set('someKey', {});
return expect(actualResponse).toEqual(expectedResponse);
});
});
describe('CacheClient.delete', () => {
@@ -132,15 +122,5 @@ describe('CacheClient', () => {
return expect(sut.delete('someKey')).rejects.toEqual(expectedError);
});
it('resolves what underlying client resolves', async () => {
const sut = new DefaultCacheClient({ client });
const expectedResponse = false;
client.delete = jest.fn().mockResolvedValue(expectedResponse);
const actualResponse = await sut.delete('someKey');
return expect(actualResponse).toEqual(expectedResponse);
});
});
});
+7 -12
View File
@@ -46,17 +46,12 @@ export interface CacheClient {
* optional TTL may also be provided, otherwise it defaults to the TTL that
* was provided when the client was instantiated.
*/
set(
key: string,
value: JsonValue,
options?: CacheSetOptions,
): Promise<boolean>;
set(key: string, value: JsonValue, options?: CacheSetOptions): Promise<void>;
/**
* Removes the given key from the cache store. Resolves true if the key
* existed, or false if not.
* Removes the given key from the cache store.
*/
delete(key: string): Promise<boolean>;
delete(key: string): Promise<void>;
}
/**
@@ -79,14 +74,14 @@ export class DefaultCacheClient implements CacheClient {
key: string,
value: JsonValue,
opts: CacheSetOptions = {},
): Promise<boolean> {
): Promise<void> {
const k = this.getNormalizedKey(key);
return await this.client.set(k, value, opts.ttl);
await this.client.set(k, value, opts.ttl);
}
async delete(key: string): Promise<boolean> {
async delete(key: string): Promise<void> {
const k = this.getNormalizedKey(key);
return await this.client.delete(k);
await this.client.delete(k);
}
/**