> **Status:** Published
> **Date:** 2026-09-12
> **Scope**: API Reference
> **Standard**: Memorio API Specification v5
>
---

# 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



```bash

npm install memorio

```



```javascript

import { cache } from 'memorio';

```



> **Classic `import`**: `cache` is also available via the global entrypoint.

> `import 'memorio/global'` exposes the same instance as `globalThis.cache`.



---



## Quick Examples



### Example 1: Basic Usage



```javascript

// Save data

cache.set('username', 'Mario');

cache.set('score', 1500);



// Read data

console.debug(cache.get('username')); // "Mario"

console.debug(cache.get('score'));    // 1500

```



### Example 2: Intermediate



```javascript

// Store objects

cache.set('user', { name: 'Luigi', level: 5 });

const user = cache.get('user');

console.debug(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



1. Use for temporary data that doesn't need persistence

2. Great for computed values or API response caching

3. Data is lost on page refresh - don't use for important data

4. Clear with `cache.removeAll()` when no longer needed
