{"id":18377,"library":"flk-core","title":"flk-cache","description":"Browser localStorage-based caching library, part of the Falak framework ecosystem. Current stable version: 0.1.67. Provides a simple API (set, get, has, remove, clear) with automatic serialization of objects/arrays, optional encryption of stored values, and configurable expiration using timestamps. Designed for use with DI container; supports ESM/CommonJS. Lightweight, no external dependencies, encrypts values by default via flk-crypto. Differentiates from general caching libraries by deep Falak integration and encryption-at-rest built-in.","status":"active","version":"0.1.67","language":"javascript","source_language":"en","source_url":null,"tags":["javascript"],"install":[{"cmd":"npm install flk-core","lang":"bash","label":"npm"},{"cmd":"yarn add flk-core","lang":"bash","label":"yarn"},{"cmd":"pnpm add flk-core","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Encrypts cache values when encryptValues config is true","package":"flk-crypto","optional":true}],"imports":[{"note":"Default export not provided; use named export 'getCache' or DI resolve pattern.","wrong":"import Cache from 'flk-cache';","symbol":"Cache","correct":"import { getCache } from 'flk-cache';"},{"note":"Cache is typically resolved through DI, not imported directly. flk-core provides the DI container.","wrong":"const cache = require('flk-cache');","symbol":"DI","correct":"import { DI } from 'flk-core';\nconst cache = DI.resolve('cache');"},{"note":"getCache is a factory function; do not use Cache as constructor.","wrong":"const { Cache } = require('flk-cache');","symbol":"getCache","correct":"import { getCache } from 'flk-cache';\nconst cache = getCache();"}],"quickstart":{"code":"import { DI } from 'flk-core';\nimport 'flk-cache';\n\n// Ensure flk-cache is registered with DI\nconst cache = DI.resolve('cache');\n\n// Set a value\ncache.set('username', 'john_doe');\n\n// Get a value\nconst username = cache.get('username');\nconsole.log(username); // 'john_doe'\n\n// Set with expiration (1 hour from now)\nconst oneHour = Date.now() + 3600000;\ncache.set('session', { token: 'abc123' }, oneHour);\n\n// Check existence\nif (cache.has('username')) {\n  console.log('Key exists');\n}\n\n// Remove a key\ncache.remove('username');\n\n// Clear all cache\ncache.clear();","lang":"javascript","description":"Demonstrates basic CRUD operations: set, get, has, remove, clear with object support and expiration."},"warnings":[{"fix":"Set 'encryptValues' to false in flk-config under 'cache' key to disable encryption.","message":"Cache values are encrypted by default if flk-crypto is installed. Encrypted values are not human-readable in localStorage.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Use Cache.FOR_ONE_HOUR constant or calculate: Date.now() + 3600000.","message":"The set() method's expiresAt parameter expects a timestamp in milliseconds (e.g., Date.now() + duration), not a duration string.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Use import { getCache } from 'flk-cache'.","message":"Using require('flk-cache') is deprecated. Import as ESM module.","severity":"deprecated","affected_versions":">=0.1.60"},{"fix":"Use only in browser environment or provide localStorage polyfill for Node.","message":"The cache relies on browser localStorage; not available in Node.js without a polyfill.","severity":"gotcha","affected_versions":">=0.1.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Install and import flk-core first: import { DI } from 'flk-core'; import 'flk-cache';","cause":"flk-core (DI container) is not installed or imported before flk-cache.","error":"TypeError: DI.resolve is not a function"},{"fix":"Use named import: import { getCache } from 'flk-cache';","cause":"Attempting default import when the module only exports named exports.","error":"Error: Module \"flk-cache\" does not provide a default export"},{"fix":"Use a polyfill like 'localstorage-polyfill' or avoid using cache server-side.","cause":"Running in environment without localStorage (e.g., Node.js, SSR).","error":"ReferenceError: localStorage is not defined"},{"fix":"Provide a numeric timestamp: cache.set('key', value, Date.now() + 60000);","cause":"Passing a non-number (e.g., string) as expiresAt parameter.","error":"Error: Cache value must be a valid timestamp for expiresAt"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}