Cache - Memorio
✅ Universal: Works in Browser, Node.js, Deno, and Edge Workers
Cache provides in-memory storage with a simple API. Data is lost on page refresh or process restart.
Installation
npm install memorio
import 'memorio';
Quick Examples
Example 1: Basic Usage
// Save data
cache.set('username', 'Mario');
cache.set('score', 1500);
// Read data
console.log(cache.get('username')); // "Mario"
console.log(cache.get('score')); // 1500
Example 2: Intermediate
// Store objects
cache.set('user', { name: 'Luigi', level: 5 });
const user = cache.get('user');
console.log(user.name); // "Luigi"
// Remove single item
cache.remove('username');
// Clear all cache
cache.removeAll();
API Reference
Methods
| Method | Parameters | Returns | Description |
|---|---|---|---|
cache.get(name) |
name: string |
any |
Get value from cache |
cache.set(name, value) |
name: string, value: any |
void |
Save value to cache |
cache.remove(name) |
name: string |
boolean |
Remove single item |
cache.removeAll() |
none |
boolean |
Clear all cache |
Storage Comparison
| Feature | Cache | Store | Session | IDB |
|---|---|---|---|---|
| Platform Support | All (universal) | Browser/Edge | Browser/Edge | Browser only |
| Lifetime | Until refresh | Forever | Until tab closes | Forever |
| Capacity | Unlimited | ~5-10 MB | ~5-10 MB | 50+ MB |
| Use case | Temporary data | User preferences | Auth tokens | Large data |
Platform Support
| Platform | Support | Notes |
|---|---|---|
| Browser | ✅ Full | In-memory, lost on refresh |
| Node.js | ✅ Full | In-memory, lost on restart |
| Deno | ✅ Full | In-memory, lost on restart |
| Edge Workers | ✅ Full | In-memory, lost on function cold start |
Best Practices
- Use for temporary data that doesn't need persistence
- Great for computed values or API response caching
- Data is lost on page refresh - don't use for important data
- Clear with
cache.removeAll()when no longer needed
Disclaimer
All content on this website, including text and images, has been generated using artificial intelligence technologies. While every effort is made to ensure quality and coherence, I do not assume responsibility for any inaccuracies, errors, or interpretations resulting from the use of this material.
Copyright and Intellectual property
All content on this website is copyrighted. Any copying, reproduction, distribution, or use of materials in any form is strictly forbidden without prior written permission. Violations will be subject to legal action in accordance with copyright law. We appreciate your understanding and compliance.
All content on this website, including text and images, has been generated using artificial intelligence technologies. While every effort is made to ensure quality and coherence, I do not assume responsibility for any inaccuracies, errors, or interpretations resulting from the use of this material.
Copyright and Intellectual property
All content on this website is copyrighted. Any copying, reproduction, distribution, or use of materials in any form is strictly forbidden without prior written permission. Violations will be subject to legal action in accordance with copyright law. We appreciate your understanding and compliance.