npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

cache-manager-soumojit-shome

v1.0.0

Published

A lightweight utility for managing cache in web applications using the browser's Cache API.

Downloads

70

Readme

Cache Management Utility

Easily manage browser cache data with this utility, leveraging the Cache API for storing, retrieving, updating, deleting, and clearing cached data. Includes support for expiration times and robust error handling.


Installation

Install the package using npm:

npm install cache-manager-soumojit-shome

Features

  • Add data to cache with customizable expiration time.
  • Retrieve and validate cached data.
  • Update existing cached data.
  • Delete specific cached data.
  • Clear all cached data for a specific cache.

Functions

AddDataIntoCache

Adds data to the cache with an expiration time.

Parameters:

  • docId (string): Unique identifier for the document.
  • dataSet (object): Data to store in the cache.
  • expirationTime (number, optional): Expiration time in milliseconds (default: 30 minutes).
  • cacheName (string): Name of the cache.
  • baseUrl (string): Base URL for generating cache keys.

Returns:

  • { success: true } if the data was added successfully.
  • { success: false, message: string, error?: string } in case of failure.

Example:

await AddDataIntoCache(
  "doc123",
  { key: "value" },
  1000 * 60 * 10, // 10 minutes expiration
  "myCache",
  "https://example.com"
);

GetDataFromCache

Retrieves data from the cache and verifies if it is still valid.

Parameters:

  • docId (string): Unique identifier for the document.
  • cacheName (string): Name of the cache.
  • baseUrl (string): Base URL for generating cache keys.

Returns:

  • { success: true, data: object } if the data was retrieved successfully.
  • { success: false, message: string, error?: string } in case of failure or expiration.

Example:

const result = await GetDataFromCache("doc123", "myCache", "https://example.com");
if (result.success) {
  console.log("Cached Data:", result.data);
} else {
  console.error("Error fetching cache:", result.message);
}

UpdateDataInCache

Updates an existing cached document by merging new data.

Parameters:

  • docId (string): Unique identifier for the document.
  • updatedDataSet (object): Data to merge with the existing cached document.
  • cacheName (string): Name of the cache.
  • baseUrl (string): Base URL for generating cache keys.

Returns:

  • { success: true, data: object } if the update was successful.
  • { success: false, message: string, error?: string } in case of failure.

Example:

await UpdateDataInCache(
  "doc123",
  { newKey: "newValue" },
  "myCache",
  "https://example.com"
);

DeleteDataFromCache

Deletes a specific document from the cache.

Parameters:

  • docId (string): Unique identifier for the document.
  • cacheName (string): Name of the cache.
  • baseUrl (string): Base URL for generating cache keys.

Returns:

  • { success: true } if the document was deleted successfully.
  • { success: false, message: string, error?: string } in case of failure.

Example:

await DeleteDataFromCache("doc123", "myCache", "https://example.com");

ClearWholeCacheData

Clears all data from a specified cache.

Parameters:

  • cacheName (string): Name of the cache.

Returns:

  • { success: true } if the cache was cleared successfully.
  • { success: false, message: string, error?: string } in case of failure.

Example:

await ClearWholeCacheData("myCache");

Notes

  • The functions rely on the Cache API, which is not available in all environments (e.g., server-side Node.js).
  • Always handle the success and error properties appropriately in your application to ensure a smooth user experience.

Exported Functions

  • AddDataIntoCache
  • GetDataFromCache
  • UpdateDataInCache
  • DeleteDataFromCache
  • ClearWholeCacheData

Developer Details

Want to learn more about the developer or explore other projects? Check out these links: