Skip to content

Installation

Sajidur edited this page Oct 26, 2024 · 1 revision

Installation 📦

To get started with SnapCache, follow these simple steps to install it in your Node.js project.

Prerequisites

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

Step-by-Step Installation

  1. 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 -y

    This command creates a new directory for your project and initializes it with a package.json file.

  2. 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.json file.

  3. Verify Installation

    After the installation, you can verify that SnapCache is installed correctly by checking your node_modules directory or by running the following command:

    npm list snapcache

    You should see SnapCache listed along with its version.

Basic Setup Example

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' }

Troubleshooting

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

Next Steps

Once you have SnapCache installed, you can dive into the Usage Guide to learn how to use it effectively in your applications.

Clone this wiki locally