PHPackages                             104corp/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. 104corp/cache

ActiveLibrary[Caching](/categories/caching)

104corp/cache
=============

PSR-16 simple cache implements written by PHP.

1.0.0(8y ago)148.6kBSD-3-ClausePHPPHP &gt;=5.5CI failing

Since Aug 3Pushed 6y ago4 watchersCompare

[ Source](https://github.com/104corp/php-cache)[ Packagist](https://packagist.org/packages/104corp/cache)[ RSS](/packages/104corp-cache/feed)WikiDiscussions master Synced yesterday

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

Cache
=====

[](#cache)

[![Build Status](https://camo.githubusercontent.com/b97186948a7800bdd28086b3daaa2312f620182cabd3bce0a4d9a9076d0fdcb1/68747470733a2f2f7472617669732d63692e636f6d2f313034636f72702f7068702d63616368652e7376673f6272616e63683d6d6173746572)](https://travis-ci.com/104corp/php-cache)[![codecov](https://camo.githubusercontent.com/35c782acec09958080892ac0544bf6b0320eb7f88d231d1bddc4a657d65b52af/68747470733a2f2f636f6465636f762e696f2f67682f313034636f72702f7068702d63616368652f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/104corp/php-cache)[![Latest Stable Version](https://camo.githubusercontent.com/18aed6e836861a413c835d8639092db34409dbf0f2e3b3c5ec64c83b280eb67d/68747470733a2f2f706f7365722e707567782e6f72672f313034636f72702f7068702d63616368652f762f737461626c65)](https://packagist.org/packages/104corp/php-cache)[![Total Downloads](https://camo.githubusercontent.com/413f0e2fcdd74aa90e239c52480d12e23f5aac2e2bbf5581e32ec6aec1ac00a0/68747470733a2f2f706f7365722e707567782e6f72672f313034636f72702f7068702d63616368652f642f746f74616c2e737667)](https://packagist.org/packages/104corp/php-cache)[![License](https://camo.githubusercontent.com/297fec2e7ed3f31de7c56dc883bd990c34ea4b60b32ef94a5dd1e636e30a453d/68747470733a2f2f706f7365722e707567782e6f72672f313034636f72702f7068702d63616368652f6c6963656e7365)](https://packagist.org/packages/104corp/php-cache)

PSR-16 simple cache implements written by PHP.

系統需求
----

[](#系統需求)

- PHP &gt;= 5.5

安裝
--

[](#安裝)

使用 [Composer](https://getcomposer.org/) 安裝

```
$ composer require 104corp/cache

```

說明
--

[](#說明)

Cache 實作遵守 [PSR-16 Simple Cache](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-16-simple-cache.md)，並提供 `CacheAwareTrait` ，可以方便地掛載在需要 Cache 的元件上；提供幾種常見的實作，可以直接套用。

因實作遵守 PSR-16 規定，如果覺得不夠用的話，也可以直接無痛改用第三方套件。

### 基本

[](#基本)

如果需要做 Cache 的話，首先先掛上 `CacheAwareTrait` ，並實作必要的方法 `getDefaultTtl()` ，接著就能開始使用了。下面是一個簡單的範例：

```
use Corp104\Cache\Util\CacheAwareTrait;

class Resource
{
    use CacheAwareTrait;

    public function getDefaultTtl()
    {
        // 60 second
        return 60;
    }

    public function getData()
    {
        $data = null;

        if (null !== $this->cache) {
            $data = $this->cache->get('some-resource-key', null);
        }

        if (null === $data) {
            $data = $this->getRealData();

            if (null !== $this->cache) {
                $this->cache->set('some-resource-key', $data, $this->getTtl());
            }
        }

        return $data;
    }

    private function getRealData()
    {
        return 'RealData';
    }
}
```

實際要使用 `Resource` 物件時，只要傳入適當的 cache driver 即可運作，如 [Symfony Cache](https://github.com/symfony/cache) 。

```
$cacheInstance = new \Symfony\Component\Cache\Simple\PhpFilesCache();

$resource = new Resource();
$resource->setCache($cacheInstance);

$data = $resource->getData();
```

### 實作

[](#實作)

- `Corp104\Cache\FileCache` - 使用 PHP 檔案當作 cache 。

### 測試替身

[](#測試替身)

Cache 元件實作 `Psr\SimpleCache\CacheInterface` ，因此可以直接使用此介面來產生 Stub / Spy / Mock 。

測試階段可使用 `Corp104\Cache\ArrayCache` 來測元件與 Cache 的互動和結果是否正常。

Contributing
------------

[](#contributing)

開發相關資訊可以參考 [CONTRIBUTING](/CONTRIBUTING.md) ，有任何問題或建議，歡迎發 issue ；如果覺得程式碼可以修更好的話，也歡迎發 PR 修正。

PR 如何使用可以參考 [Git 官方文件](https://git-scm.com/book/zh-tw/v2/GitHub-%E5%8F%83%E8%88%87%E4%B8%80%E5%80%8B%E5%B0%88%E6%A1%88)。

###  Health Score

32

—

LowBetter than 69% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity28

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity58

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

Unknown

Total

1

Last Release

3256d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/20872dcc4b888075f03819d5470db8198ffcc5f9edb791aba5f007e34355a6c9?d=identicon)[MilesChou](/maintainers/MilesChou)

---

Top Contributors

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

---

Tags

cachephp

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/104corp-cache/health.svg)

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

###  Alternatives

[laravel/framework

The Laravel Framework.

34.8k543.8M20.1k](/packages/laravel-framework)[illuminate/contracts

The Illuminate Contracts package.

706130.3M13.3k](/packages/illuminate-contracts)[algolia/algoliasearch-client-php

API powering the features of Algolia.

69735.1M159](/packages/algolia-algoliasearch-client-php)[moonshine/moonshine

Laravel administration panel

1.3k253.1k81](/packages/moonshine-moonshine)[flow-php/flow

PHP ETL - Extract Transform Load - Data processing framework

85036.3k](/packages/flow-php-flow)[flow-php/etl

PHP ETL - Extract Transform Load - Abstraction

378604.0k104](/packages/flow-php-etl)

PHPackages © 2026

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