-
Notifications
You must be signed in to change notification settings - Fork 1
Installation
To get started with SnapCache, follow these simple steps to install it in your Node.js project.
Before installing SnapCache, ensure you have the following:
-
Node.js: SnapCache requires Node.js to run. You can download it from the official Node.js website.
-
npm (Node Package Manager): npm is typically included with Node.js installations. Verify it by running the following command in your terminal:
npm -v
-
Create a New Project (if needed)
If you don’t already have a project, you can create one by running:
mkdir my-project cd my-project npm init -yThis command creates a new directory for your project and initializes it with a
package.jsonfile. -
Install SnapCache
Use npm to install SnapCache by running the following command:
npm install snapcache@latest
This command installs the latest version of SnapCache and adds it as a dependency in your
package.jsonfile. -
Verify Installation
After the installation, you can verify that SnapCache is installed correctly by checking your
node_modulesdirectory or by running the following command:npm list snapcache
You should see SnapCache listed along with its version.
Here’s a quick example to help you get started after installation:
const SnapCache = require('snapcache');
// Create a SnapCache instance
const cache = new SnapCache({ maxSize: 100, defaultTTL: 30000 }); // Default TTL of 30 seconds
// Store a value in the cache
cache.set('user:123', { name: 'Alice' }, { ttl: 60000 }); // 1 minute TTL
// Retrieve the value
const value = cache.get('user:123');
console.log(value); // { name: 'Alice' }If you encounter any issues during installation, consider the following:
-
Node.js Version: Ensure you are using a compatible version of Node.js. SnapCache is designed for Node.js 12 and above.
-
npm Cache: If you experience problems, try clearing the npm cache:
npm cache clean --force
Once you have SnapCache installed, you can dive into the Usage Guide to learn how to use it effectively in your applications.
📄 License: MIT License
📞 Support: If you have any questions or need assistance, feel free to reach out on our Discord.