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

ActiveLibrary

topthink/think-cache
====================

Cache Manager

v3.0.1(1y ago)3333.2k↓45.9%14[13 issues](https://github.com/top-think/think-cache/issues)Apache-2.0PHPPHP &gt;=8.0

Since Jan 25Pushed 1y ago3 watchersCompare

[ Source](https://github.com/top-think/think-cache)[ Packagist](https://packagist.org/packages/topthink/think-cache)[ RSS](/packages/topthink-think-cache/feed)WikiDiscussions 3.0 Synced today

READMEChangelog (10)Dependencies (2)Versions (15)Used By (0)

think-cache
===========

[](#think-cache)

用于PHP缓存管理（PHP 8.0+），支持`PSR-16`缓存规范。

主要特性包括：

- 支持多缓存通道设置及切换
- 支持缓存数据递增/递减
- 支持门面调用
- 内置File/Redis/Memcache/Memcached/Wincache
- 支持缓存标签
- 支持`PSR-16`缓存规范

安装
--

[](#安装)

```
composer require topthink/think-cache

```

用法：
---

[](#用法)

```
use think\facade\Cache;

// 缓存配置
Cache::config([
	'default'	=>	'file',
	'stores'	=>	[
		'file'	=>	[
			'type'   => 'File',
			// 缓存保存目录
			'path'   => './cache/',
			// 缓存前缀
			'prefix' => '',
			// 缓存有效期 0表示永久缓存
			'expire' => 0,
		],
		'redis'	=>	[
			'type'   => 'redis',
			'host'   => '127.0.0.1',
			'port'   => 6379,
			'prefix' => '',
			'expire' => 0,
		],
	],
]);
// 设置缓存
Cache::set('val','value',600);
// 判断缓存是否设置
Cache::has('val');
// 获取缓存
Cache::get('val');
// 删除缓存
Cache::delete('val');
// 清除缓存
Cache::clear();
// 读取并删除缓存
Cache::pull('val');
// 不存在则写入
Cache::remember('val',10);

// 对于数值类型的缓存数据可以使用
// 缓存增+1
Cache::inc('val');
// 缓存增+5
Cache::inc('val',5);
// 缓存减1
Cache::dec('val');
// 缓存减5
Cache::dec('val',5);

// 使用缓存标签
Cache::tag('tag_name')->set('val','value',600);
// 删除某个标签下的缓存数据
Cache::tag('tag_name')->clear();
// 支持指定多个标签
Cache::tag(['tag1','tag2'])->set('val2','value',600);
// 删除多个标签下的缓存数据
Cache::tag(['tag1','tag2'])->clear();

// 使用多种缓存类型
$redis = Cache::store('redis');

$redis->set('var','value',600);
$redis->get('var');
```

更多内容可以参考 [https://doc.thinkphp.cn/v8\_0/caches.html](https://doc.thinkphp.cn/v8_0/caches.html)

###  Health Score

47

—

FairBetter than 94% of packages

Maintenance37

Infrequent updates — may be unmaintained

Popularity40

Moderate usage in the ecosystem

Community17

Small or concentrated contributor base

Maturity76

Established project with proven stability

 Bus Factor1

Top contributor holds 89.2% 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 ~196 days

Recently: every ~182 days

Total

14

Last Release

432d ago

Major Versions

v1.1 → v2.02019-04-29

v2.0.7 → v3.0.02025-01-15

PHP version history (3 changes)v1.0PHP &gt;=5.6.0

v2.0PHP &gt;=7.1.0

v3.0.0PHP &gt;=8.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/7858077?v=4)[topthink](/maintainers/topthink)[@topthink](https://github.com/topthink)

---

Top Contributors

[![liu21st](https://avatars.githubusercontent.com/u/1111670?v=4)](https://github.com/liu21st "liu21st (33 commits)")[![evalor](https://avatars.githubusercontent.com/u/26944445?v=4)](https://github.com/evalor "evalor (2 commits)")[![AxiosLeo](https://avatars.githubusercontent.com/u/13862149?v=4)](https://github.com/AxiosLeo "AxiosLeo (1 commits)")[![ichynul](https://avatars.githubusercontent.com/u/10061650?v=4)](https://github.com/ichynul "ichynul (1 commits)")

---

Tags

cachecache-service

### Embed Badge

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

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

###  Alternatives

[laravel/framework

The Laravel Framework.

34.6k500.1M15.0k](/packages/laravel-framework)[phpoffice/phpspreadsheet

PHPSpreadsheet - Read, Create and Write Spreadsheet documents in PHP - Spreadsheet engine

13.9k286.2M1.1k](/packages/phpoffice-phpspreadsheet)[maatwebsite/excel

Supercharged Excel exports and imports in Laravel

12.6k140.5M622](/packages/maatwebsite-excel)[mobiledetect/mobiledetectlib

Mobile\_Detect is a lightweight PHP class for detecting mobile devices. It uses the User-Agent string combined with specific HTTP headers to detect the mobile environment.

10.7k155.8M383](/packages/mobiledetect-mobiledetectlib)[topthink/framework

The ThinkPHP Framework.

2.8k3.2M1.2k](/packages/topthink-framework)[illuminate/contracts

The Illuminate Contracts package.

703120.6M8.5k](/packages/illuminate-contracts)

PHPackages © 2026

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