
Research
Malicious npm Packages Impersonate Flashbots SDKs, Targeting Ethereum Wallet Credentials
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
swork-cache
Advanced tools
swork-cache is caching middleware for swork applications and is built with TypeScript and async methods.
import { Swork } from "swork";
import { Router } from "swork-router";
import { strategies } from "swork-cache";
const app = new Swork();
const router = new Router();
router.get("/api/foos", strategies.backgroundFetch());
app.use(router.routes());
app.listen();
Install via npm:
npm install swork-cache
Install via yarn:
yarn add swork-cache
backgroundFetch
This strategy will immediately return a value from the cache if it exists. If a cache entry is found, a fetch for the latest version of the asset will occur in the background and update the cache. If a cache entry is not found, the request will respond with the fetch of the asset immediately after updating the cache.
cacheFirst
This strategy will immediately return a value from the cache if it exists. If a cache entry is not found, the request will respond with the fetch of the asset immediately after updating the cache. Once an item is in the cache, there will be no subsequent requests to get the latest version.
networkFirst
This strategy will attempt to fetch the asset from the source and will pass on the response if there is no error. In the case of an error, the strategy will attempt to find a match in the cache.
networkOnly
This strategy only attempts to get the asset from the network source and does not utilize caching.
All of the pre-defined cache strategies implement the CacheStrategy
type. To provide a custom caching strategy, just define a method matching the CacheStrategy
signature.
/**
* Defines a cache strategy delegate. 'key' defaults to service worker version.
*/
type CacheStrategy = (cacheKey?: string) => (context: FetchContext, next: () => Promise<void>) => Promise<void> | void;
The cacheKey
parameter is intended to specify a specific cache and defaults to the service worker version found in configuration.version
provided by swork
.
In addition to caching strategies, swork-cache
provides event handlers to simplify management of cache entries.
preCache
preCache
is an event handler that will cache any provided urls during the install phase of the service worker.
import { events } from "swork-cache";
// ...
app.on("install", events.install.preCache([
// array of urls to pre-cache
]);
clearCacheOnUpdate
clearCacheOnUpdate
is an event handler that will delete unnecessary cache entries during the activate phase of the service worker. Which cache entries to remove is determined by an overridable whitelist of keys that defaults to the configuration.version
provided by swork
.
import { events } from "swork-cache";
// ...
app.on("activate", events.activate.clearCacheOnUpdate());
// or
app.on("activate", events.activate.clearCacheOnUpdate({
whitelist: ["api-data"],
ignoreCase: true
}));
If you are using swork or any of its related middlewares, please let me know on gitter. I am always looking for feedback or additional middleware ideas.
FAQs
Caching implementation using the swork framework.
The npm package swork-cache receives a total of 2 weekly downloads. As such, swork-cache popularity was classified as not popular.
We found that swork-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.
Research
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
Security News
Ruby maintainers from Bundler and rbenv teams are building rv to bring Python uv's speed and unified tooling approach to Ruby development.
Security News
Following last week’s supply chain attack, Nx published findings on the GitHub Actions exploit and moved npm publishing to Trusted Publishers.