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

ActiveLibrary[Caching](/categories/caching)

smart-cache/smart-cache
=======================

Modify the cache refresh time as the number of requests changes

1.2.1(7y ago)040PHPPHP &gt;=5.6.0

Since Aug 21Pushed 5y ago1 watchersCompare

[ Source](https://github.com/zhanjinbiao/smart-cache)[ Packagist](https://packagist.org/packages/smart-cache/smart-cache)[ RSS](/packages/smart-cache-smart-cache/feed)WikiDiscussions master Synced 2d ago

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

smart-cache
===========

[](#smart-cache)

Modify the cache refresh time as the number of requests changes

##### 使用方式

[](#使用方式)

- 引入smartCache.php文件

```
require __DIR__.'/vendor/smart-cache/smart-cache/src/SmartCache.php';

```

- 配置文件 /smart-cache/src/config.php

> default属性表示缓存方式，暂时只有redis

redis\[default\] 使用的时候默认的配置，可以添加任意组的配置然后使用，配置格式：

```
'default' => [
    'host'     => 'localhost',
    'password' => null,
    'port'     => 6379,
    'database' => 0,
],
'addTest' => [
    'host'     => 'localhost',
    'password' => null,
    'port'     => 6379,
    'database' => 1,
]

```

- 调用实例

```
$a = 10;
$smartCache = new SmartCache();

//更换为addTest的配置
$smartCache->connection('addTest');
/**保存缓存
*第一个参数为保存的键，
*第二个为保存的值可以是字符串或者数组，
*第三个参数为保存的时长，
*/
$res = $smartCache->saveCache('test',['name'=>'czhan','level'=>999],10);

//获取缓存，只需传入键值
$data = $smartCache->getCache('test');

//清楚缓存
$data = $smartCache->deleteCache('test')

//以数组形式传入配置，第一个参数为host，
//第二个参数为part（默认为6379），第三参数为密码（没有则为null，或者不传）
//第四个参数为选择的database可以不传
$smartCache->connection(['127.0.0.1','6379',null,0]);

$smartCache->connection(['127.0.0.1','6379','test']);

$smartCache->connection(['127.0.0.1','6379']);

$smartCache->connection(['127.0.0.1']);

```

> 并且支持redis对象原本的所有方法，keys等操作。

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community7

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

2823d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/acc87d714ddc0fe994c28aef20b0c489fdde4d53e46ff08770ad2576eb5fa845?d=identicon)[zhanjinbiao](/maintainers/zhanjinbiao)

---

Top Contributors

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

---

Tags

phpcache

### Embed Badge

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

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

###  Alternatives

[awssat/laravel-visits

Laravel Redis visits counter for Eloquent models

975163.6k2](/packages/awssat-laravel-visits)[swayok/alternative-laravel-cache

Replacements for Laravel's redis and file cache stores that properly implement tagging idea. Powered by cache pool implementations provided by http://www.php-cache.com/

202541.1k6](/packages/swayok-alternative-laravel-cache)[eftec/cacheone

A Cache library with minimum dependency

103.5k4](/packages/eftec-cacheone)

PHPackages © 2026

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