
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
@flk/session
Advanced tools
The cache system is built on LocaleStorage API.
flk install flk-cache
OR
npm install flk-cache
Alias: cache.
Once you resolve the cache object you can use the methods below.
class HomePage {
/**
* {@inheritDoc}
*/
constructor(cache) {
this.cache = cache;
}
}
set(key: String, value: any, expiresAt: Number = Cache.FOREVER): Self
This method accepts any type of values, the cache engine will handle it automatically, so if you want to store object, you don't have to JSON.stringify it, the package will take care of it.
The expiresAt parameter is used to determine until when the value should be stored in.
Please note that this method accepts a valid timestamp number, i.e
Date.now().
The default value for expiresAt is set to Cache.FOREVER which mean the value will not be removed from the cache until the user clears the browser history.
There are some useful constants for cache expiration time.
let cache = DI.resolve('cache');
cache.set('name', 'Hasan');
// It can also store objects
let user = {
name: 'Hasan',
address: 'Some street address',
};
cache.set('user', user);
// storing arrays is acceptable as well
let users = [{
name: 'Hasan',
address: 'Some street address',
}, {
name: 'John Doe',
address: 'Another address',
}];
cache.set('users', users);
// cache for one hour
cache.set('accessToken', MyAccessToken, Cache.FOR_ONE_HOUR);11
get(key: String, defaultValue: any = null): any|null
Retrieve value from cache.
If the key doesn't exist, defaultValue will be returned instead.
let cache = DI.resolve('cache');
// if the given key exists
let name = cache.get('name'); // Hasan
// if the given key doesn't exists, return null
let age = cache.get('age'); // null
// if the given key doesn't exists, return the given default value instead.
let email = cache.get('email', 'my-email@sitename.com'); // my-email@sitename.com
has(key: String): Boolean
Determine if the given key exists in cache.
let cache = DI.resolve('cache');
if (cache.has('name')) {
// do something
}
remove(key: String): void
Remove the given key if exists in cache storage.
let cache = DI.resolve('cache');
cache.remove('name');
clear(): void
Clear all cache values.
let cache = DI.resolve('cache');
cache.clear();
Available configurations for cache in Application configurations.
Main Configuration key: cache
| key | Type | Default value | Description |
|---|---|---|---|
| encryptValues | Boolean | true | If set to true, any value will be encrypted using the Crypto package. |
It's recommended to set the type of the encryptionValue in your
config.jsin the beginning of your application development as it works on all the cached values.
| constant | Description |
|---|---|
Cache.FOR_ONE_HOUR | Cache the value for one hour. |
Cache.FOR_TWO_HOURS | Cache the value for two hours. |
Cache.FOR_ONE_DAY | Cache the value for one day. |
Cache.FOR_ONE_WEEK | Cache the value for one week. |
Cache.FOR_ONE_MONTH | Cache the value for one month. |
Cache.FOR_ONE_YEAR | Cache the value for one year. |
Cache.FOREVER | Cache the value until the visitor clears the browser history. |
FAQs
A cache engine for storing data in session storage.
We found that @flk/session demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.