{"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,"search_vec":"'0.1.67':19 'api':23 'automat':30 'base':7 'browser':4 'built':79 'built-in':78 'cach':3,8,67 'clear':28 'configur':40 'contain':49 'crypto':63 'current':16 'deep':70 'default':59 'depend':55 'design':44 'di':48 'differenti':64 'ecosystem':15 'encrypt':35,56,75 'encryption-at-rest':74 'esm/commonjs':51 'expir':41 'extern':54 'falak':13,71 'flk':2,62 'flk-cach':1 'flk-crypto':61 'framework':14 'general':66 'get':25 'integr':72 'javascript':81 'librari':9,68 'lightweight':52 'localstorag':6 'localstorage-bas':5 'objects/arrays':33 'option':34 'part':10 'provid':20 'remov':27 'rest':77 'serial':31 'set':24 'simpl':22 'stabl':17 'store':37 'support':50 'timestamp':43 'use':42,46 'valu':38,57 'version':18 'via':60","created_at":"2026-04-25T07:37:54.914891+00:00","updated_at":"2026-04-25T07:37:54.914891+00:00","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,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":"","cli_version":null,"type":"library","homepage":"https://falakframework.com","github":null,"docs":null,"changelog":null,"pypi":null,"npm":"https://www.npmjs.com/package/flk-core","openapi_spec":null,"status_page":null,"smithery":null,"categories":["database","auth-security"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-17","next_check":"2026-07-24","install_tag":null}}