Gathering detailed insights and metrics for @jointly/cache-candidate-plugin-base
Gathering detailed insights and metrics for @jointly/cache-candidate-plugin-base
This is a library providing types needed to create a plugin for cache-candidate.
npm install @jointly/cache-candidate-plugin-base
Typescript
Module System
Node Version
NPM Version
67.3
Supply Chain
98.6
Quality
82.3
Maintenance
100
Vulnerability
100
License
TypeScript (67.47%)
JavaScript (28.62%)
Shell (3.92%)
Total Downloads
6,626
Last Day
3
Last Week
7
Last Month
469
Last Year
5,120
5 Stars
49 Commits
1 Watching
1 Branches
3 Contributors
Minified
Minified + Gzipped
Latest Version
2.0.0
Package Id
@jointly/cache-candidate-plugin-base@2.0.0
Unpacked Size
14.91 kB
Size
4.63 kB
File Count
6
NPM Version
8.19.2
Node Version
14.16.0
Publised On
06 Jun 2023
Cumulative downloads
Total Downloads
Last day
0%
3
Compared to previous day
Last week
-76.7%
7
Compared to previous week
Last month
838%
469
Compared to previous month
Last year
396.1%
5,120
Compared to previous year
This is a basic repository for @jointly/cache-candidate that provides types needed to create a cache-candidate plugin.
This library is not meant to be used directly, but rather as a dependency for better types when creating your own plugin.
This library is used by all First Party Plugins of the cache-candidate ecosystem.
You can develop a library without using this library as this only provides some types, but we strongly recommend using it.
To create a plugin, you have to declare a variable of type CacheCandidatePlugin
.
This variable must be exported, so that the plugin can be loaded by cache-candidate.
1import { CacheCandidatePlugin, Hooks } from '@jointly/cache-candidate-plugin-base'; 2 3export const myPlugin: CacheCandidatePlugin = { 4 name: 'myPlugin', 5 hooks: [ 6 { 7 hook: Hooks.SETUP, 8 action: async (payload, additionalParameters) => { 9 // Do something 10 console.log('Hooks.SETUP', payload, additionalParameters); 11 } 12 }, 13 { 14 hook: Hooks.INIT, 15 action: async (payload, additionalParameters) => { 16 // Do something 17 console.log('Hooks.INIT', payload, additionalParameters); 18 } 19 }, 20 { 21 hook: Hooks.EXECUTION_PRE, 22 action: async (payload, additionalParameters) => { 23 // Do something 24 console.log('Hooks.EXECUTION_PRE', payload, additionalParameters); 25 } 26 }, 27 { 28 hook: Hooks.EXECUTION_POST, 29 action: async (payload, additionalParameters) => { 30 // Do something 31 console.log('Hooks.EXECUTION_POST', payload, additionalParameters); 32 } 33 }, 34 { 35 hook: Hooks.DATACACHE_RECORD_ADD_PRE, 36 action: async (payload, additionalParameters) => { 37 // Do something 38 console.log('Hooks.DATACACHE_RECORD_ADD_PRE', payload, additionalParameters); 39 } 40 }, 41 { 42 hook: Hooks.DATACACHE_RECORD_ADD_POST, 43 action: async (payload, additionalParameters) => { 44 // Do something 45 console.log('Hooks.DATACACHE_RECORD_ADD_POST', payload, additionalParameters); 46 } 47 }, 48 { 49 hook: Hooks.DATACACHE_RECORD_DELETE_PRE, 50 action: async (payload, additionalParameters) => { 51 // Do something 52 console.log('Hooks.DATACACHE_RECORD_DELETE_PRE', payload, additionalParameters); 53 } 54 }, 55 { 56 hook: Hooks.DATACACHE_RECORD_DELETE_POST, 57 action: async (payload, additionalParameters) => { 58 // Do something 59 console.log('Hooks.DATACACHE_RECORD_DELETE_POST', payload, additionalParameters); 60 } 61 }, 62 { 63 hook: Hooks.CACHE_HIT, 64 action: async (payload, additionalParameters) => { 65 // Do something 66 console.log('Hooks.CACHE_HIT', payload, additionalParameters); 67 } 68 } 69 ] 70};
In the example above, we created a plugin named myPlugin
that logs the payload of each hook.
The additionalParameters
argument is an object that can be passed to the cache-candidate when calling its hooks.
1import { cacheCandidate } from '@jointly/cache-candidate'; 2import { myPlugin } from 'my-plugin'; 3 4const myCachedFunction = cacheCandidate(myFunction, { 5 // ... options 6 plugins: [ 7 { 8 ...myPlugin, 9 additionalParameters: { 10 foo: 'bar' 11 } 12 } 13 ] 14});
If you don't need additionalParameters, you can simply pass the plugin to the cache-candidate.
1import { cacheCandidate } from '@jointly/cache-candidate'; 2import { myPlugin } from 'my-plugin'; 3 4const myCachedFunction = cacheCandidate(myFunction, { 5 // ... options 6 plugins: [ 7 myPlugin 8 ] 9});
The CacheCandidatePlugin
is an object composed of the following properties:
name
: The name of the plugin. This name will be used to identify the plugin in the logs.hooks
: An array of ActionableHook
that will be executed by cache-candidate.An ActionableHook is a hook associated with an action that can be executed by cache-candidate.
It is composed of the following properties:
hook
: The hook to execute.action
: The action to execute when the hook is triggered.All hooks are called only when the cache-candidate is executed in runtime.
The following hooks are available:
SETUP
: Triggered when the cache-candidate firstly wraps the function/method.INIT
: Triggered when the candidate process is initialized.EXECUTION_PRE
: Triggered before the execution of the function/method wrapped in the cache-candidate.EXECUTION_POST
: Triggered after the execution of the function/method wrapped in the cache-candidate.DATACACHE_RECORD_ADD_PRE
: Triggered before the addition of a record in the cache.DATACACHE_RECORD_ADD_POST
: Triggered after the addition of a record in the cache.DATACACHE_RECORD_DELETE_PRE
: Triggered before the deletion of a record in the cache.DATACACHE_RECORD_DELETE_POST
: Triggered after the deletion of a record in the cache.CACHE_HIT
: Triggered when a cache hit occurs, before the result is returned. This also applies when a Running Query
is returned (Please, refer to this paragraph and this paragraph for additional information).Actions are functions that are executed by the cache-candidate when a hook is triggered.
Please, refer to the cache-candidate docs for more information about the arguments and their properties.
They take two arguments:
payload
: The payload of the hook. It is composed of the following properties:
options
: The options of the cache-candidate.key
: The key of the function/method wrapped in the cache-candidate. In case of SETUP
, the key is an empty string ""
.timeoutCache
: The map containing the timeout bombs of the cache-candidate.runningQueryCache
: The running query cache of the cache-candidate.timeframeCache
: The timeframe cache of the cache-candidate.fnArgs
: The arguments of the function/method wrapped in the cache-candidate. In case of SETUP
, the arguments are an empty array []
.internals
: Internal functions and objects of the cache-candidate.getDataCacheRecord
: A function that gets a record from the data cache.addDataCacheRecord
: A function that adds a record to the data cache.deleteDataCacheRecord
: A function that deletes a record from the data cache.isDataCacheRecordExpired
: A function that checks if a record is expired.getDataCacheKey
: A function that gets the key of a record in the data cache.getExceedingAmount
: A function that gets the exceeding amount of a record in the data cache.
result
(only for EXECUTION_POST
and CACHE_HIT
): The result of the function/method wrapped in the cache-candidate.additionalParameters
: The additional parameters passed to the plugin when calling its hooks.No vulnerabilities found.
No security vulnerabilities found.