Security News
New Python Packaging Proposal Aims to Solve Phantom Dependency Problem with SBOMs
PEP 770 proposes adding SBOM support to Python packages to improve transparency and catch hidden non-Python dependencies that security tools often miss.
@astro-my/cache
Advanced tools
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"
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
PEP 770 proposes adding SBOM support to Python packages to improve transparency and catch hidden non-Python dependencies that security tools often miss.
Security News
Socket CEO Feross Aboukhadijeh discusses open source security challenges, including zero-day attacks and supply chain risks, on the Cyber Security Council podcast.
Security News
Research
Socket researchers uncover how threat actors weaponize Out-of-Band Application Security Testing (OAST) techniques across the npm, PyPI, and RubyGems ecosystems to exfiltrate sensitive data.