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.
node-ts-cache
Advanced tools
Readme
Simple and extensible caching module supporting decorators.
npm install node-ts-cache
Note: The underlying storage layer must be installed separately.
Storage | Install |
---|---|
memory | npm install node-ts-cache-storage-memory |
node-fs | npm install node-ts-cache-storage-node-fs |
ioredis | npm install node-ts-cache-storage-ioredis |
Caches function response using the given options. Works with the above listed storages. By default, uses all arguments to build an unique key.
@Cache(container, options)
options
:
ttl
: (Default: 60) Number of seconds to expire the cachte itemisLazy
: (Default: true) If true, expired cache entries will be deleted on touch. If false, entries will be deleted after the given ttl.isCachedForever
: (Default: false) If true, cache entry has no expiration.calculateKey(data => string)
: (Default: JSON.stringify combination of className, methodName and call args)
data
:
className
: The class name for the method being decoratedmethodName
: The method name being decoratedargs
: The arguments passed to the method when calledNote: @Cache will consider the return type of the function. If the return type is a thenable, it will stay that way, otherwise not.
import { Cache, CacheContainer } from 'node-ts-cache'
import { MemoryStorage } from 'node-ts-cache-storage-memory'
const userCache = new CacheContainer(new MemoryStorage())
class MyService {
@Cache(userCache, {ttl: 60})
public async getUsers(): Promise<string[]> {
return ["Max", "User"]
}
}
import { CacheContainer } from 'node-ts-cache'
import { MemoryStorage } from 'node-ts-cache-storage-memory'
const myCache = new CacheContainer(new MemoryStorage())
class MyService {
public async getUsers(): Promise<string[]> {
const cachedUsers = await myCache.getItem<string[]>("users")
if (cachedUsers) {
return cachedUsers
}
const newUsers = ["Max", "User"]
await myCache.setItem("users", newUsers, {ttl: 60})
return newUsers
}
}
This project uses debug to log useful caching information. Set environment variable DEBUG=node-ts-cache to enable logging.
This project follows the monorepo architecture using lerna. To start development and run tests for all the packages, run:
git clone git@github.com:havsar/node-ts-cache.git
cd node-ts-cache
npm i
npm run bootstrap
npm run test
FAQs
Simple and extensible caching module supporting decorators
The npm package node-ts-cache receives a total of 7,452 weekly downloads. As such, node-ts-cache popularity was classified as popular.
We found that node-ts-cache 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
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.