feat(catbox-memory): add v4 (#30427)

This commit is contained in:
Simon Schick
2018-11-16 08:37:52 -08:00
committed by Andy
parent 112cc3e073
commit 44650cfbe7
4 changed files with 81 additions and 0 deletions
@@ -0,0 +1,8 @@
import * as CatboxMemory from 'catbox-memory';
const client = new CatboxMemory<string>({
allowMixedContent: true,
cloneBuffersOnGet: false,
maxByteSize: 1024,
minCleanupIntervalMsec: 1000,
});
+47
View File
@@ -0,0 +1,47 @@
// Type definitions for catbox-memory 4.0
// Project: https://github.com/hapijs/catbox-memory#readme
// Definitions by: Simon Schick <https://github.com/SimonSchick>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.8
import { ClientApi } from 'catbox';
interface CatboxMemory<T> extends ClientApi<T> {}
// tslint:disable-next-line:no-unnecessary-class
declare class CatboxMemory<T> implements ClientApi<T> {
constructor(options?: CatboxMemory.Options);
}
declare namespace CatboxMemory {
interface Options {
/**
* Sets an upper limit on the number of bytes that can be stored in the cache.
* Once this limit is reached no additional items will be added to the cache until some expire.
* The utilized memory calculation is a rough approximation and must not be relied on.
* @default 104857600 (100MB).
*/
maxByteSize?: number;
/**
* The minimum number of milliseconds in between each cache cleanup.
* @default 1000 (1 second)
*/
minCleanupIntervalMsec?: number;
/**
* by default, all data is cached as JSON strings, and converted to an object using JSON.parse() on retrieval.
* By setting this option to true, Buffer data can be stored alongside the stringified data.
* Buffers are not stringified, and are copied before storage to prevent the value from changing while in the cache.
* @default false
*/
allowMixedContent?: boolean;
/**
* by default, buffers stored in the cache with allowMixedContent set to true are copied when they are set but not when they are retrieved.
* This means a change to the buffer returned by a get() will change the value in the cache. To prevent this,
* set cloneBuffersOnGet to true to always return a copy of the cached buffer.
* @default false
*/
cloneBuffersOnGet?: boolean;
}
}
export = CatboxMemory;
+23
View File
@@ -0,0 +1,23 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"catbox-memory-tests.ts"
]
}
+3
View File
@@ -0,0 +1,3 @@
{
"extends": "dtslint/dt.json"
}