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

ActiveLibrary[Caching](/categories/caching)

costalong/swoft-cache
=====================

swoft-cache component for swoft framework

1.12(4y ago)0363Apache-2.0PHPPHP &gt;7.1

Since Jul 6Pushed 4y ago1 watchersCompare

[ Source](https://github.com/costa92/swoft-cache)[ Packagist](https://packagist.org/packages/costalong/swoft-cache)[ RSS](/packages/costalong-swoft-cache/feed)WikiDiscussions main Synced 4d ago

READMEChangelog (3)Dependencies (7)Versions (4)Used By (0)

Swoft-cache
===========

[](#swoft-cache)

Swoft-cache component for swoft framework

Install
-------

[](#install)

- install by composer

```
composer require root/swoft-cache
```

- update bean.php file

```
 Cache::MANAGER    => [
        'class'   => CacheManager::class,
        'adapter' => bean(Cache::ADAPTER),
        'lockAdapter' => Cache::LOCK
    ],
    Cache::ADAPTER    => [
        'class'        => RedisAdapter::class,
        'serializer'   => bean(Cache::SERIALIZER),
        'redis'        => bean('redis.pool'),
        "openListener" => true   // is open listener function  eg: false  setKey config invalid
        'setKey'       => \Costalong\Swoft\Cache\Handle\SetKeyListener\SetKeyLogs::class
    ],
    //cache原子锁配置
    Cache::LOCK => [
        'class' => RedisLock::class,
        'redis' => bean('redis.pool'),
        'prefix' => 'lock:'
    ],

    Cache::SERIALIZER => [
        'class' => PhpSerializer::class
    ],

    'redis'              => [
        'class'    => \Swoft\Redis\RedisDb::class,
        'host'     => '127.0.0.1',
        'port'     => 6379,
        'database' => 1,
        'option'   => [
            'prefix' => 'swoft:',
        ]
    ],
    'redis.pool' => [
        'class'       => Swoft\Redis\Pool::class,
        'redisDb'     => bean('redis'),
        'minActive'   => 10,
        'maxActive'   => 20,
        'maxWait'     => 0,
        'maxWaitTime' => 0,
        'maxIdleTime' => 60,
    ]
```

- use example

```
  Cache::set("test",111,100);
  $data = Cache::get("test");

 if (Cache::lock('foo', 1000)->get()) {
  // 获取锁定10秒...
  Cache::lock('foo')->release();
}

 Cache::lock('foo', 10)->block(5, function () {
            // 等待最多5秒后获取锁定...
            return false;
});

 $value = Cache::remember('users', 30, function () {
      return 111;
 });

 //数据永久存储  需要调用delete清除
Cache::forever('key', 'value');
```

LICENSE
-------

[](#license)

The Component is open-sourced software licensed under the [Apache license](LICENSE).

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity48

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

Total

3

Last Release

1724d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/8148c7f8ba4894af278e4a028c6efb32f14b4c63dd4749c969245c4b55eb06e3?d=identicon)[costa92](/maintainers/costa92)

---

Top Contributors

[![kart-io](https://avatars.githubusercontent.com/u/111626169?v=4)](https://github.com/kart-io "kart-io (2 commits)")

---

Tags

swooleswoftswoft-component

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[swoft/redis

swoft redis component

12168.4k16](/packages/swoft-redis)[swoft/auth

Auth component for swoft

127.2k1](/packages/swoft-auth)

PHPackages © 2026

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