PHPackages                             code-corner/performance-cache - 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. code-corner/performance-cache

ActiveLibrary[Caching](/categories/caching)

code-corner/performance-cache
=============================

A caching library for PHP performance optimization supporting multiple caching strategies.

1.0.1(1y ago)08MITPHPPHP &gt;=7.4.2

Since Jul 21Pushed 1y ago1 watchersCompare

[ Source](https://github.com/yashgupta-dev/caching-performance-optimization)[ Packagist](https://packagist.org/packages/code-corner/performance-cache)[ RSS](/packages/code-corner-performance-cache/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (2)Versions (3)Used By (0)

PerformanceCache Package
========================

[](#performancecache-package)

The **PerformanceCache** package provides a robust caching solution that adheres to the PSR-16 (Simple Cache) interface, allowing developers to efficiently manage caching operations in PHP applications.

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

[](#installation)

You can install the PerformanceCache package via Composer. Run the following command in your terminal:

```
composer require codecorners/performance-cache
```

Usage
-----

[](#usage)

### Initializing the Cache

[](#initializing-the-cache)

To start using the cache, initialize an instance of `Cache`. By default, it uses `FileCacheHandler` for file-based caching:

```
use CodeCorner\PerformanceCache\Cache;
use CodeCorner\PerformanceCache\FileCacheHandler;

// Initialize cache with default handler (FileCacheHandler)
$cache = new Cache();
```

You can optionally pass a custom cache handler to the constructor:

```
use CodeCorner\PerformanceCache\Cache;
use App\CustomCacheHandler; // Replace with your custom cache handler

// Initialize cache with custom handler
$customHandler = new CustomCacheHandler();
$cache = new Cache($customHandler);
```

### Basic Cache Operations

[](#basic-cache-operations)

#### Setting a Cache Value

[](#setting-a-cache-value)

```
$key = 'my_key';
$value = 'my_value';
$ttl = 3600; // Optional TTL (time-to-live) in seconds

if ($cache->set($key, $value, $ttl)) {
    echo "Value successfully cached!\n";
} else {
    echo "Failed to cache the value.\n";
}
```

#### Getting a Cached Value

[](#getting-a-cached-value)

```
$key = 'my_key';
$defaultValue = 'default_value'; // Optional default value if key not found

$cachedValue = $cache->get($key, $defaultValue);

echo "Cached Value: $cachedValue\n";
```

#### Deleting a Cached Value

[](#deleting-a-cached-value)

```
$key = 'my_key';

if ($cache->delete($key)) {
    echo "Cache entry successfully deleted!\n";
} else {
    echo "Failed to delete the cache entry.\n";
}
```

#### Clearing All Cached Values

[](#clearing-all-cached-values)

```
if ($cache->clear()) {
    echo "Cache cleared successfully!\n";
} else {
    echo "Failed to clear the cache.\n";
}
```

#### Working with Multiple Cache Entries

[](#working-with-multiple-cache-entries)

##### Getting Multiple Cache Entries

[](#getting-multiple-cache-entries)

```
$keys = ['key1', 'key2', 'key3'];
$defaultValue = 'default_value'; // Optional default value if any key is not found

$cachedValues = $cache->getMultiple($keys, $defaultValue);

foreach ($cachedValues as $key => $value) {
    echo "Key: $key, Value: $value\n";
}
```

##### Setting Multiple Cache Entries

[](#setting-multiple-cache-entries)

```
$values = [
    'key1' => 'value1',
    'key2' => 'value2',
    'key3' => 'value3',
];
$ttl = 3600; // Optional TTL for all entries

if ($cache->setMultiple($values, $ttl)) {
    echo "Multiple values successfully cached!\n";
} else {
    echo "Failed to cache multiple values.\n";
}
```

##### Deleting Multiple Cache Entries

[](#deleting-multiple-cache-entries)

```
$keysToDelete = ['key1', 'key2', 'key3'];

if ($cache->deleteMultiple($keysToDelete)) {
    echo "Multiple cache entries deleted successfully!\n";
} else {
    echo "Failed to delete multiple cache entries.\n";
}
```

#### Checking if a Key Exists in Cache

[](#checking-if-a-key-exists-in-cache)

```
$key = 'my_key';

if ($cache->has($key)) {
    echo "Key '$key' exists in cache.\n";
} else {
    echo "Key '$key' does not exist in cache.\n";
}
```

### Error Handling

[](#error-handling)

The `Cache` class provides basic error handling for cache operations. If an operation fails (e.g., cache read, write, delete), it logs the error message using `error_log()`.

License
-------

[](#license)

This package is licensed under the MIT License. See the [LICENSE](./LICENSE) file for details.

Author
------

[](#author)

Written by Yash Gupta.

---

Replace placeholders such as `Yash Gupta` with your actual name or preferred pseudonym. Ensure the `LICENSE` file is present in your project directory and contains the appropriate license text for distribution.

This README file provides comprehensive guidance for developers looking to integrate the **PerformanceCache** package into their PHP projects, covering installation, basic usage examples, error handling considerations, and licensing information. Adjust the examples and instructions as per your specific implementation and documentation style.

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance33

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 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.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

666d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/ccf3a637954d7adc187e222a65119214e8bc54866324187fa5503ee6c5d19ece?d=identicon)[yashgupta-dev](/maintainers/yashgupta-dev)

---

Top Contributors

[![yashgupta-dev](https://avatars.githubusercontent.com/u/39840278?v=4)](https://github.com/yashgupta-dev "yashgupta-dev (2 commits)")

---

Tags

cachecomposerphpsimple-cache

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/code-corner-performance-cache/health.svg)

```
[![Health](https://phpackages.com/badges/code-corner-performance-cache/health.svg)](https://phpackages.com/packages/code-corner-performance-cache)
```

###  Alternatives

[laminas/laminas-cache

Caching implementation with a variety of storage options, as well as codified caching strategies for callbacks, classes, and output

1076.9M130](/packages/laminas-laminas-cache)[cache/adapter-common

Common classes for PSR-6 adapters

11124.4M38](/packages/cache-adapter-common)[cache/filesystem-adapter

A PSR-6 cache implementation using filesystem. This implementation supports tags

705.8M82](/packages/cache-filesystem-adapter)[cache/array-adapter

A PSR-6 cache implementation using a php array. This implementation supports tags

548.3M151](/packages/cache-array-adapter)[cache/redis-adapter

A PSR-6 cache implementation using Redis (PhpRedis). This implementation supports tags

523.9M27](/packages/cache-redis-adapter)[cache/simple-cache-bridge

A PSR-6 bridge to PSR-16. This will make any PSR-6 cache compatible with SimpleCache.

423.1M27](/packages/cache-simple-cache-bridge)

PHPackages © 2026

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