| Recommend this page to a friend! |
| Packages of tomloprod | Memoize | README.md | Download |
|
|||||||||||||||||||||
<div align="center"> ? MemoizeHigh-performance memoization library for PHP <p align="center"> </p> </div> ? About MemoizeMemoize is a lightweight PHP library designed to implement memoization and function caching techniques with ease. Transform expensive function calls into lightning-fast cache lookups with zero configuration. ? Features<table> <tr> <td width="50%"> ? Key-based Memoization Cache function results with custom keys ? Single Execution Functions run only once, results cached forever ?? Namespaces Organize cache by classes or contexts </td> <td width="50%"> ? LRU Cache Automatic memory management with size limits ? Simple API Intuitive facade and helper functions ? Cache Analytics Built-in statistics and monitoring </td> </tr> </table> ? Quick StartInstallation
Basic Usage?? Namespace OrganizationIf you want to get the most out of the package and better organize your memoization, we recommend using namespaces. When using namespaces, if you use a
? Key-based MemoizationYou can also not use namespaces and just memoize keys.
? Single Execution Functions
? Memory ManagementThe library uses an LRU (Least Recently Used) algorithm to automatically manage memory and prevent unlimited cache growth. How does LRU work?
- Maintains a record of the access order for cache entries
- When the maximum limit ( This ensures that the most relevant and frequently used data remains in memory, while obsolete data is automatically removed.
? Advanced Examples???? Performance Optimization
? API ReferenceCore Methods<table> <tr><td width="30%"><strong>Method</strong></td><td><strong>Description</strong></td></tr> <tr><td> memo(?string $key, callable $callback) </td><td> Key-based memoization - Execute callback and cache result by key. Returns cached value on subsequent calls. </td></tr> <tr><td> once(callable $callback) </td><td> Single execution - Returns a wrapper function that executes the callback only once, caching the result forever. </td></tr> <tr><td> for(string $class) </td><td> Namespace organization - Set namespace to organize cache by class/context. Automatically cleared after use. </td></tr> </table> Cache Management<table> <tr><td width="30%"><strong>Method</strong></td><td><strong>Description</strong></td></tr> <tr><td> has(string $key): bool </td><td>Check if a key exists in cache</td></tr> <tr><td> forget(string $key): bool </td><td>Remove specific key from cache</td></tr> <tr><td> flush(): void </td><td>Clear all cached values</td></tr> <tr><td> setMaxSize(?int $maxSize): void </td><td>Set maximum entries (LRU eviction)</td></tr> <tr><td> getStats(): array </td><td>Get detailed cache statistics</td></tr> </table> ?? Requirements & Installation
????? ContributingContributions are welcome, and are accepted via pull requests. Please review these guidelines before submitting any pull requests. Memoize was created by Tomás López and open-sourced under the MIT license. |