{"id":29178269,"url":"https://github.com/knfs-library/bamimi-cache","last_synced_at":"2025-07-01T18:33:01.199Z","repository":{"id":272246721,"uuid":"915952191","full_name":"knfs-library/bamimi-cache","owner":"knfs-library","description":"A lightweight, file-based caching library designed for Node.js applications. It provides flexible caching with optional compression, expiration handling, and keyword search capabilities. The library is easy to use and integrates seamlessly into modern applications","archived":false,"fork":false,"pushed_at":"2025-04-17T18:41:24.000Z","size":105,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-19T00:51:48.073Z","etag":null,"topics":["bamimi","cache","cache-control","cache-storage","framework","nodejs"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/@knfs-tech/bamimi-cache","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/knfs-library.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-01-13T07:04:36.000Z","updated_at":"2025-04-17T18:35:26.000Z","dependencies_parsed_at":"2025-01-13T08:24:33.981Z","dependency_job_id":"1e748167-b001-4a80-bb4c-bb6183d39d47","html_url":"https://github.com/knfs-library/bamimi-cache","commit_stats":null,"previous_names":["knfs-library/bamimi-cache"],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/knfs-library/bamimi-cache","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/knfs-library%2Fbamimi-cache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/knfs-library%2Fbamimi-cache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/knfs-library%2Fbamimi-cache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/knfs-library%2Fbamimi-cache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/knfs-library","download_url":"https://codeload.github.com/knfs-library/bamimi-cache/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/knfs-library%2Fbamimi-cache/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263017166,"owners_count":23400439,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bamimi","cache","cache-control","cache-storage","framework","nodejs"],"created_at":"2025-07-01T18:31:17.512Z","updated_at":"2025-07-01T18:33:01.167Z","avatar_url":"https://github.com/knfs-library.png","language":"JavaScript","readme":"\u003cp align=\"center\"\u003e\n  \u003cbr\u003e\n\t\u003ca href=\"https://github.com/knfs-library/bamimi-cache/actions/workflows/unit-test.yml\" alt=\"github\"\u003e\n\t\u003cimg src=\"https://github.com/knfs-library/bamimi-cache/actions/workflows/unit-test.yml/badge.svg\" alt=\"Github Actions\" /\u003e\n\t\u003c/a\u003e\n\u003ca href=\"https://img.shields.io/github/license/knfs-library/bamimi-cache\" alt=\"License\"\u003e\n\t\u003cimg src=\"https://img.shields.io/github/license/knfs-library/bamimi-cache\" alt=\"License\" /\u003e\n\u003c/a\u003e\n\u003ca href=\"https://img.shields.io/github/contributos/knfs-library/bamimi-cache\" alt=\"License\"\u003e\n\t\u003cimg src=\"https://img.shields.io/github/contributors/knfs-library/bamimi-cache\" alt=\"License\" /\u003e\n\u003c/a\u003e\n\u003ca href=\"https://img.shields.io/github/languages/code-size/knfs-library/bamimi-cache\" alt=\"License\"\u003e\n\t\u003cimg src=\"https://img.shields.io/github/languages/code-size/knfs-library/bamimi-cache\" alt=\"License\" /\u003e\n\u003c/a\u003e\n\u003c/p\u003e\n\n# About **BAMIMI Cache**\n\n**BAMIMI Cache** is a lightweight, file-based caching library designed for Node.js applications. It provides flexible caching with optional compression, expiration handling, and keyword search capabilities. The library is easy to use and integrates seamlessly into modern applications.\n\n---\n\n## Installation\n\nInstall BAMIMI Cache via **npm** or **yarn**:\n\n```bash\nnpm i @knfs-tech/bamimi-cache\n# OR\nyarn add @knfs-tech/bamimi-cache\n```\n\n---\n\n## Features\n\n- **File-based Caching**: Store data directly on the file system for fast and efficient access.\n- **Compression**: Reduce file sizes with Snappy compression.\n- **Expiration Handling**: Automatically delete cached entries after a specified duration.\n- **Keyword Search**: Search through cached entries using keywords with `AND`/`OR` logic.\n- **Logging**: Enable optional logging for debugging and monitoring.\n- **Flexible Configuration**: Set up default settings for expiration, compression, and cache directory.\n\n---\n\n## Basic Usage\n\n### Example\n\n```javascript\nconst CacheFile = require('@knfs-tech/bamimi-cache');\n\n// Initialize the cache system\nconst cache = new CacheFile({\n  folder: './my-cache', // Custom cache folder\n  autoCompress: true,   // Automatically compress data\n  log: true,            // Enable logging\n});\ncache.setup()\n\n// Store data in the cache\nawait cache.set('user:123', JSON.stringify({ name: 'John Doe' }), { expire: 60000 });\n\n// Retrieve data from the cache\nconst userData = await cache.get('user:123');\nconsole.log(JSON.parse(userData));\n\n// Check if a key exists\nconst exists = await cache.exist('user:123');\nconsole.log(exists ? 'Key exists' : 'Key does not exist');\n\n// Delete a cache entry\nawait cache.del('user:123');\n```\n\n---\n\n## API Reference\n\n### **Constructor**\n\n#### `new CacheFile(config)`\nCreates a new instance of BAMIMI Cache.\n\n| Parameter             | Type    | Default                  | Description                                 | Support Version     |\n| --------------------- | ------- | ------------------------ | ------------------------------------------- |-------------|\n| `config.folder`       | String  | `projectPath + /cache` | Directory to store cached files.              | \u003e= 1.0.2\n| `config.expire`       | Number  | `0`                      | Default expiration time in milliseconds, (0 is not expire)    |   \u003e= 1.0.2  |\n| `config.autoCompress` | Boolean | `false`                  | Enable auto-compression for cached content. | \u003e= 1.0.2     |\n| `config.log`          | Boolean | `false`                  | Enable or disable logging.                  | \u003e= 1.0.2     |   \n| `config.peakDuration`  | Number  | `3000`                   | Allows peak time to use cache to store the results returned when getting, to increase query speed. If peakDuration is 0, it means it is not used.  | \u003e= 1.1.3     |\n| `config.maxSize`  | Number  | `0`                   | Default max size of cache content in bytes, (0 is not verify).  | \u003e= 1.2.9     |\n| `config.logHandle`  | Number  | use `console.log`                   | Function handle log  | \u003e= 1.3.0 (Latest)     |\n| `config.errorHandle`  | Number  | use `throw new Error`                  | Function handle error.  | \u003e= 1.3.0     |\n\n---\n\n### **Methods**\n\n#### **`setup()`**\nInitialize configuration files\n\n#### **`set(key, content, options)`**\nStores data in the cache.\n\n| Parameter          | Type          | Description                               |\n| ------------------ | ------------- | ----------------------------------------- |\n| `key`              | String        | Unique identifier for the cache entry.    |\n| `content`          | String        | Content to cache.                         |\n| `options.compress` | Boolean       | Enable compression for this entry.        |\n| `options.expire`   | Number        | Expiration time in milliseconds.          |\n| `options.search`   | Array\u003cString\u003e | Keywords to enable search for this entry. |\n\n---\n\n#### **`get(key)`**\nRetrieves cached content by its key.\n\n| Parameter | Type   | Description                      |\n| --------- | ------ | -------------------------------- |\n| `key`     | String | Unique identifier for the cache. |\n\n**Returns:** `Promise\u003cString\u003e` - Cached content.\n\n---\n\n#### **`exist(key)`**\nChecks if a key exists in the cache.\n\n| Parameter | Type   | Description                      |\n| --------- | ------ | -------------------------------- |\n| `key`     | String | Unique identifier for the cache. |\n\n**Returns:** `Boolean` - `true` if the key exists, otherwise `false`.\n\n---\n\n#### **`del(key)`**\nDeletes a cached entry by its key.\n\n| Parameter | Type   | Description                      |\n| --------- | ------ | -------------------------------- |\n| `key`     | String | Unique identifier for the cache. |\n\n---\n\n#### **`search(keywords, logic)`**\nSearches for cached entries based on keywords.\n\n| Parameter  | Type                | Default | Description                       |\n| ---------- | ------------------- | ------- | --------------------------------- |\n| `keywords` | Array\u003cString\u003e       | `[]`    | Keywords to search for.           |\n| `logic`    | String (`AND`/`OR`) | `AND`   | Logic to apply during the search. |\n\n**Returns:** `Array\u003cString\u003e` - Matching cache keys.\n\n---\n\n#### **`publish(key, message)`** (\u003e= 1.5.1)\nPublish event\n\n| Parameter  | Type                | Default | Description                       |\n| ---------- | ------------------- | ------- | --------------------------------- |\n| `key` | String       |     | Key or event.           |\n| `message`    | any |    | Message publish to event. |\n\n---\n\n#### **`subscribe(key, listener)`** (\u003e= 1.5.1)\nSubscribe event\n\n| Parameter  | Type                | Default | Description                       |\n| ---------- | ------------------- | ------- | --------------------------------- |\n| `key` | String       |     | Key or event.           |\n| `logic`    | function(message) |    | Listen event publish. |\n\n*Ex:*\n```javascript\nconst storage = new CacheFile(configDefault)\nstorage.setup()\n\nstorage.subscribe(\"event-1\", async (message) =\u003e {\n\t\tconsole.log(\"listener 1\", message)\n})\n\nstorage.publish(\"event-1\", contentNumber)\n```\n\n---\n\n### Configuration Example\n\nTo customize the cache configuration:\n\n```javascript\nconst cache = new CacheFile({\n  folder: './cache-directory',\n  expire: 60000,         // Default expiration time: 60 seconds\n  autoCompress: true,    // Enable automatic compression\n  log: true,             // Enable logging\n});\n```\n\n---\n\n## Advanced Features\n\n### **Compression**\nUses [Snappy](https://github.com/google/snappy) for fast and lightweight compression. To enable compression:\n\n```javascript\nawait cache.set('key', 'content', { compress: true });\n```\n\n### **Expiration Handling**\nAutomatically removes expired entries:\n\n```javascript\nawait cache.set('tempKey', 'tempData', { expire: 5000 }); // Expires in 5 seconds\n```\n\n---\n\n## Contributions\n\nWe welcome contributions! Please create a pull request or submit issues on GitHub.\n\n---\n\n## License\n\n**BAMIMI Cache** is open-source software licensed under the [MIT License](LICENSE).","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fknfs-library%2Fbamimi-cache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fknfs-library%2Fbamimi-cache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fknfs-library%2Fbamimi-cache/lists"}