dercoder/simple-cache-shared-memory

1.0.0 2024-07-18 11:41 UTC

This package is auto-updated.

Last update: 2024-11-19 09:37:14 UTC


README

A simple cache implementation using shared memory in PHP.

Installation

You can install the package using Composer:

composer require dercoder/simple-cache-shared-memory

Usage

use DerCoder\SimpleCache\SharedMemory\SharedMemoryCache;
use Psr\SimpleCache\CacheInterface;

$cache = new SharedMemoryCache('1M'); // 1MB shared memory segment

// Set cache items
$cache->set('key1', 'value1');
$cache->set('key2', [1, 2, 3], 60); // with TTL of 60 seconds

// Get cache items
$value1 = $cache->get('key1');
$value2 = $cache->get('key2');

// Check if a cache item exists
$hasKey1 = $cache->has('key1');

// Delete cache items
$cache->delete('key1');

TODO

  • Lock functions so multiple threads will not overwrite values
  • Second release for PHP 8+

Contributing

Contributions are welcome! Please feel free to open an issue or submit a pull request.

License

This project is licensed under the MIT License - see the LICENSE file for details.