Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
@astro-my/cache
Advanced tools
Readme
This service reads from env variables to connect from redis store. This service supports cluster and simple redis setup.
cacheHost // required, default to 127.0.0.1,
cachePort // required, default to 6379
cacheCluster // optional, 1 - true, 0 - false
cachePassword // optional
For cluster, give the multiple host comma seperated.
Or you can provide these, configuration in configure function
This library will first check env variables, then user provided configuration. If both not found it will use default values
const cache = require('@astro-my/cache');
cache.configure();
OR
-----
cache.configure({
cacheHost: '127.0.0.1',
cachePort: 6379
});
cache.run();
The get method on the Cache is used to retrieve items from the cache.
const value = async cache.get('key');
The has method may be used to determine if an item exists in the cache. This method will return false if the value is null or false:
const exists = async cache.has('key');
Sometimes you may wish to retrieve an item from the cache, but also store a default value if the requested item doesn't exist. For example, you may wish to retrieve all users from the cache or, if they don't exist, retrieve them from the database and add them to the cache.
const exists = async cache.remember('key', seconds, () => { return Users.fetch(); });
If the item does not exist in the cache, the Closure passed to the remember method will be executed and its result will be placed in the cache with ttl of seconds passed as second argument.
If you need to retrieve an item from the cache and then delete the item, you may use the pop method. Like the get method, null will be returned if the item does not exist in the cache:
const value = async cache.pop('key');
Returns the values associated with the specified fields in the hash stored at key.
const values = async cache.multiget('key', [...fieldKey (String)]);
You may use the put method to store items in the cache. When you place an item in the cache, you need to specify the number of seconds for which the value should be cached: P.S: all expiry values are in seconds. If not provided, the key will be stored permenantely
const stored = async cache.put('key', value, expiry);
The method will return true if the item is stored to the cache
The put method will only add the item to the cache if it does not already exist in the cache store. The method will return true if the item is actually added to the cache. Otherwise, the method will return false:
const stored = async cache.put('key', value, expiry);
Sets the specified fields to their respective values in the hash stored at key. This command overwrites any specified fields already existing in the hash. If key does not exist, a new key holding a hash is created.
cache.multiset('key', { field1: 'value1', field2: 'value2' }, expiry);
You may remove items from the cache using the destroy method:
cache.destroy('key');
FAQs
Cache wrapper to use ioredis conviently"
The npm package @astro-my/cache receives a total of 1 weekly downloads. As such, @astro-my/cache popularity was classified as not popular.
We found that @astro-my/cache demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 6 open source maintainers 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
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.