Download the PHP package sanovskiy/simple-cache without Composer
On this page you can find all versions of the php package sanovskiy/simple-cache. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download sanovskiy/simple-cache
More information about sanovskiy/simple-cache
Files in sanovskiy/simple-cache
Package simple-cache
Short Description A simple and transparent caching library for PHP with multiple driver support
License MIT
Informations about the package simple-cache
Simple Cache
A simple and transparent caching library for PHP with multiple driver support.
Features
- Lightweight and easy-to-use API
- Multiple drivers: File, Memcached, Redis, Database, Mock
- Built-in support for the "remember" pattern
- Mock driver for testing
Installation
Requirements
- PHP 8.0 or higher
- For File driver: No additional requirements
- For Memcached driver:
ext-memcached(version >= 3.0 recommended) - For Redis driver:
ext-redis(version >= 5.0 recommended) - For Database driver:
ext-pdowith appropriate database driver (e.g.,ext-pdo-mysql) - For Mock driver: No additional requirements
Configuration
Files
Memcached
Redis
SQL database
Note: The DatabaseCacheDriver automatically creates cache table with columns key, value, expires_at, created_at, and updated_at (with an index on expires_at) if it doesn't exist. Ensure the database user has CREATE TABLE and INDEX permissions.
Mock cache for testing
Usage
Basic usage
Using the "remember" pattern:
Drivers
Simple Cache supports the following drivers:
- File: Stores cache in files on the filesystem.
- Config:
directory(path to cache directory),file_extension(e.g.,.cache)
- Config:
- Memcached: Uses a Memcached server for distributed caching.
- Config:
servers(array of [host, port]),prefix(key prefix)
- Config:
- Redis: Uses a Redis server for high-performance caching.
- Config:
host,port,prefix,database,password,timeout
- Config:
- Database: Stores cache in an SQL database (e.g., MySQL, PostgreSQL).
- Config:
dsn,username,password,table
- Config:
- Mock: In-memory driver for testing, does not persist data.
- Config:
emulate_failures(bool),log_operations(bool)
- Config:
Testing
To run tests locally, ensure Memcached, Redis, and MySQL are running and PHP extensions (ext-memcached, ext-redis, ext-pdo_mysql) are installed. Then run:
To run the tests using Docker Compose:
To generate a code coverage report:
Why Simple Cache?
Simple Cache is designed to be a lightweight, transparent, and easy-to-use caching library for PHP. Unlike other caching libraries that come with complex configurations or heavy dependencies, Simple Cache focuses on:
- Simplicity: Intuitive API with minimal setup.
- Flexibility: Supports multiple drivers (File, Memcached, Redis, Database, Mock) out of the box.
- Testability: Includes a Mock driver for easy unit testing.
- Lightweight: Minimal dependencies for better performance in small to medium projects.
Roadmap
- Add support for PSR-6 (Caching Interface) in future versions
- Add support for additional drivers (e.g., APCu)
Contributing
Found a bug or have an idea? Open an issue or submit a pull request on GitHub.
License
This library is licensed under the MIT License