Skip to content

Repository files navigation

Utopia Cache

Important

This repository is a read-only mirror of the utopia-php monorepo. Development happens in packages/cache — please open issues and pull requests there.

Total DownloadsDiscord

Utopia framework cache library is simple and lite library for managing application cache storing, loading and purging. This library is aiming to be as simple and easy to learn and use. This library is maintained by the Appwrite team.

Although this library is part of the Utopia Framework project it is dependency free and can be used as standalone with any other PHP project or framework.

Getting started

Install using Composer:

composer require utopia-php/cache

File System Adapter

<?phprequire_once__DIR__ . '/../../vendor/autoload.php';
useUtopia\Cache\Cache;
useUtopia\Cache\Adapter\Filesystem;
$cache = newCache(newFilesystem('/cache-dir'));
$key = 'data-from-example.com';
$data = $cache->load($key, 60 * 60 * 24 * 30 * 3/* 3 months */);
if(!$data) {
$data = file_get_contents('https://example.com');
$cache->save($key, $data);
}
echo$data;

Adapters

AdapterNotes
FilesystemFiles on disk, with optional streaming reads.
MemoryIn-process array, useful in tests.
NoneStores nothing, for turning caching off.
Redisphpredis, with reconnect and leases.
Redis\MultiplexingMany Swoole coroutines over one Redis connection — see the multiplexing guide.
RedisClusterphpredis against a Redis cluster.
MemcachedMemcached over the binary protocol.
HazelcastHazelcast over its Memcached protocol.
ShardingSpreads keys across several adapters.
PoolChecks an adapter out of a utopia-php/pools pool per call.
CircuitBreakerWraps an adapter so a failing cache stops being called.

System requirements

The library requires PHP 8.4 or later. The Redis, Memcached and Hazelcast adapters need the matching extension — see the suggest block in composer.json.

Tests

The unit tier needs nothing running:

composer test

The end-to-end tier runs on the host against this package's services:

docker compose up -d --wait
composer test:e2e
docker compose down -v

Copyright and license

The MIT License (MIT) http://www.opensource.org/licenses/mit-license.php

About

Lite & fast micro PHP cache library that is **easy to use**.

Topics

Resources

Stars

33 stars

Watchers

6 watching

Forks

Releases

Packages

Used by

Contributors

Languages