PHPackages                             gokhankurtulus/jsoncache - 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. gokhankurtulus/jsoncache

ActiveLibrary[Caching](/categories/caching)

gokhankurtulus/jsoncache
========================

A simple PHP caching library.

1.0.2(2y ago)265MITPHPPHP ^8.0 || ^8.1

Since Jun 18Pushed 2y ago1 watchersCompare

[ Source](https://github.com/gokhankurtulus/jsoncache)[ Packagist](https://packagist.org/packages/gokhankurtulus/jsoncache)[ RSS](/packages/gokhankurtulus-jsoncache/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (3)DependenciesVersions (4)Used By (0)

JsonCache
=========

[](#jsoncache)

[![License: MIT](https://camo.githubusercontent.com/08cef40a9105b6526ca22088bc514fbfdbc9aac1ddbf8d4e6c750e3a88a44dca/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d626c75652e737667)](LICENSE)[![PHP Version](https://camo.githubusercontent.com/d4b5fa4adf514144779a7864904c5e15236c0e798635240c7f6ce9a455657b80/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d382e302532422d626c75652e737667)](https://camo.githubusercontent.com/d4b5fa4adf514144779a7864904c5e15236c0e798635240c7f6ce9a455657b80/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d382e302532422d626c75652e737667)[![Release](https://camo.githubusercontent.com/2791779d3c7df8a04b9a90d9ea674703f7be5becd658cbeb0f38448a48fd63d6/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f676f6b68616e6b757274756c75732f6a736f6e63616368652e737667)](https://camo.githubusercontent.com/2791779d3c7df8a04b9a90d9ea674703f7be5becd658cbeb0f38448a48fd63d6/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f676f6b68616e6b757274756c75732f6a736f6e63616368652e737667)

JsonCache is a simple PHP library that provides simple caching mechanism for data. It enables efficient storage and retrieval of JSON data by employing a file-based storage approach.

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

[](#installation)

You can install the library using Composer. Run the following command:

```
composer require gokhankurtulus/jsoncache
```

Usage
-----

[](#usage)

### Initialization

[](#initialization)

To start using JsonCache, you need to create an instance of the `JsonCache` class. You can pass an optional configuration array to customize the cache behavior.

```
use JsonCache\JsonCache;

$config = [
    'storage_path' => '/path/to/storage',
    'index_file' => 'index.json',
    'lifetime' => 60, // seconds
    'force_create_storage_path' => true,
    'force_create_index_file' => true,
    'json_flags' => JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES,
    'compress' => true
];

$jsonCache = new JsonCache($config);
```

### Caching Data

[](#caching-data)

You can store JSON data using the `set` method. Provide a unique key and the data you want to cache.

```
$jsonCache->set('my_key', ['name' => 'John Doe', 'age' => 30]);
```

### Retrieving Data

[](#retrieving-data)

To retrieve cached data, use the `get` method and provide the key by default it returns as array.

```
$data = $jsonCache->get('my_key');
if ($data !== null) {
    // Use the cached data
    echo $data['name']; // John Doe
    echo $data['age']; // 30
} else {
    // Data not found or expired
}
```

### Checking Existence

[](#checking-existence)

You can check if a key exists in the cache using the `has` method.

```
if ($jsonCache->has('my_key')) {
    // Key exists in the cache
} else {
    // Key does not exist
}
```

### Deleting Data

[](#deleting-data)

To remove a key from the cache, use the `delete` method.

```
$jsonCache->delete('my_key');
```

### Clear Cache

[](#clear-cache)

To clear cache, use the `clear` method.

```
$jsonCache->clear();
```

### Methods

[](#methods)

You can also use these methods after creating an instance of `JsonCache`.

```
$jsonCache->getCacheSize('my_key'); // Returns the size of the key in bytes
$jsonCache->getLifetime(); // Returns cache instance lifetime
$jsonCache->setLifetime(120); // Sets cache instance lifetime to 120 seconds
$jsonCache->isCompressed(); // Returns cache compress status
$jsonCache->getConfig(); // Returns config array
$jsonCache->getStoragePath(); // Returns config's storage path
$jsonCache->getIndexFile(); // Returns config's index file path
$jsonCache->getJsonFlags(); // Returns config's json flags
```

License
-------

[](#license)

JsonCache is open-source software released under the [MIT License](LICENSE). Feel free to modify and use it in your projects.

Contributions
-------------

[](#contributions)

Contributions to JsonCache are welcome! If you find any issues or have suggestions for improvements, please create an issue or submit a pull request on the [GitHub repository](https://github.com/gokhankurtulus/jsoncache).

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity55

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 ~11 days

Total

3

Last Release

1042d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/7a8dc07ce25345005f0d5c4e7eb9b9dc7348c25f9fe09375dcfe6950404f7e06?d=identicon)[gokhankurtulus](/maintainers/gokhankurtulus)

---

Top Contributors

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

---

Tags

cachejsonjsoncachephpjsoncachejsoncache

### Embed Badge

![Health badge](/badges/gokhankurtulus-jsoncache/health.svg)

```
[![Health](https://phpackages.com/badges/gokhankurtulus-jsoncache/health.svg)](https://phpackages.com/packages/gokhankurtulus-jsoncache)
```

###  Alternatives

[aplus/cache

Aplus Framework Cache Library

161.6M4](/packages/aplus-cache)[cache/void-adapter

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

183.0M44](/packages/cache-void-adapter)[spekkionu/assetcachebuster

Prefixes asset urls with a unique hash which will allow invalidation of asset files cached by the browser.

3243.2k](/packages/spekkionu-assetcachebuster)[ihor/cachalot

Cache a lot in a proper way (APC, XCache, Memcached, Redis, Couchbase)

2528.1k](/packages/ihor-cachalot)

PHPackages © 2026

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