PHPackages                             dm1tra/cache-library - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Caching](/categories/caching)
4. /
5. dm1tra/cache-library

ActiveLibrary[Caching](/categories/caching)

dm1tra/cache-library
====================

A simple caching library for PHP

00PHP

Since Feb 11Pushed 1y ago1 watchersCompare

[ Source](https://github.com/Dm1tra/CacheLibrary)[ Packagist](https://packagist.org/packages/dm1tra/cache-library)[ RSS](/packages/dm1tra-cache-library/feed)WikiDiscussions master Synced 1w ago

READMEChangelogDependenciesVersions (1)Used By (0)

Simple Caching Library for PHP
==============================

[](#simple-caching-library-for-php)

Installation
------------

[](#installation)

```
composer require dm1tra/cache-library
```

Usage

> File Backend

```
require 'vendor/autoload.php';

try {
    $cache = new CacheLibrary\Cache('file', ['cache_dir' => '/path/to/cache']);
    $data = $cache->get('my_key');
    if (!$data) {
        $data = performExpensiveOperation();
        $cache->set('my_key', $data, 3600);
    }
    useData($data);
} catch (\Exception $e) {
    echo "Error: " . $e->getMessage();
}
```

> Redis Backend

```
require 'vendor/autoload.php';

try {
    $cache = new CacheLibrary\Cache('redis', ['host' => '127.0.0.1', 'port' => 6379]);
    $data = $cache->get('my_key');
    if (!$data) {
        $data = performExpensiveOperation();
        $cache->set('my_key', $data, 3600);
    }
    useData($data);
} catch (\Exception $e) {
    echo "Error: " . $e->getMessage();
}
```

> Memcached Backend

```
require 'vendor/autoload.php';

try {
    $cache = new CacheLibrary\Cache('memcached', ['host' => '127.0.0.1', 'port' => 11211]);
    $data = $cache->get('my_key');
    if (!$data) {
        $data = performExpensiveOperation();
        $cache->set('my_key', $data, 3600);
    }
    useData($data);
} catch (\Exception $e) {
    echo "Error: " . $e->getMessage();
}
```

> Methods

**set(string $key, $value, int $ttl = 3600): bool**Set a value in the cache with a specified time-to-live (TTL).

Parameters:

- $key: The key of the item to store.
- $value: The value to store.
- $ttl: The time-to-live in seconds.

Returns : True on success, false on failure. **get(string $key)**Get a value from the cache. Parameters :

- $key: The key of the item to retrieve. Returns : The value of the item or null if not found. **has(string $key): bool**Check if an item exists in the cache.

Parameters :

- $key: The key of the item to check. Returns : True if the item exists, false otherwise. **delete(string $key): bool**Delete an item from the cache.

Parameters :

- $key: The key of the item to delete. Returns : True on success, false on failure. **clear(): bool**Clear all items from the cache.
- Returns : True on success, false on failure.

###  Health Score

13

—

LowBetter than 1% of packages

Maintenance30

Infrequent updates — may be unmaintained

Popularity0

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity16

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/6278214?v=4)[Артур](/maintainers/Dm1tra)[@Dm1tra](https://github.com/Dm1tra)

---

Top Contributors

[![Dm1tra](https://avatars.githubusercontent.com/u/6278214?v=4)](https://github.com/Dm1tra "Dm1tra (4 commits)")

### Embed Badge

![Health badge](/badges/dm1tra-cache-library/health.svg)

```
[![Health](https://phpackages.com/badges/dm1tra-cache-library/health.svg)](https://phpackages.com/packages/dm1tra-cache-library)
```

###  Alternatives

[iazaran/smart-cache

Smart Cache is a caching optimization package designed to enhance the way your Laravel application handles data caching. It intelligently manages large data sets by compressing, chunking, or applying other optimization strategies to keep your application performant and efficient.

21114.2k](/packages/iazaran-smart-cache)[phpfastcache/phpssdb

PHP SSDB Driver for phpFastCache

14736.9k1](/packages/phpfastcache-phpssdb)[rapidwebltd/rw-file-cache

RW File Cache is a PHP File-based Caching Library. Its syntax is designed to closely resemble the PHP memcache extension.

15196.8k7](/packages/rapidwebltd-rw-file-cache)[yuzuru-s/redis-recommend

Wrapping Redis's sorted set APIs for specializing recommending operations.

392.9k](/packages/yuzuru-s-redis-recommend)[ichhabrecht/intcache

Turn uncachable page objects into cacheable links

193.9k](/packages/ichhabrecht-intcache)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
