PHPackages                             autoframe/components-socket-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. autoframe/components-socket-cache

ActiveLibrary[Caching](/categories/caching)

autoframe/components-socket-cache
=================================

PHP client - cache server alternative for memcached / redis. Including cache manager based on namespace priority rules

1.0.0(2y ago)07MITPHPPHP &gt;=7.4

Since Apr 4Pushed 2y ago1 watchersCompare

[ Source](https://github.com/autoframe/components-socket-cache)[ Packagist](https://packagist.org/packages/autoframe/components-socket-cache)[ Docs](https://github.com/autoframe)[ RSS](/packages/autoframe-components-socket-cache/feed)WikiDiscussions main Synced 1mo ago

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

Autoframe is a low level framework that is oriented on SOLID flexibility
========================================================================

[](#autoframe-is-a-low-level-framework-that-is-oriented-on-solid-flexibility)

[![Build Status](https://github.com/autoframe/components-socket-cache/workflows/PHPUnit-tests/badge.svg)](https://github.com/autoframe/components-socket-cache/actions?query=branch:main)[![License: The 3-Clause BSD License](https://camo.githubusercontent.com/8398050213eb0e069fd3dc1c4309690c7d767a97cae7d1c8b392c34eb1d4d4ca/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6175746f6672616d652f636f6d706f6e656e74732d736f636b65742d6361636865)](https://opensource.org/license/bsd-3-clause/)[![Packagist Version](https://camo.githubusercontent.com/0017b1b6e9fd64aff3e4a6cede1223493ad0db4ca6e26c30553dbd75b1fc48ba/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6175746f6672616d652f636f6d706f6e656e74732d736f636b65742d63616368653f6c6162656c3d7061636b6167697374253230737461626c65)](https://camo.githubusercontent.com/0017b1b6e9fd64aff3e4a6cede1223493ad0db4ca6e26c30553dbd75b1fc48ba/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6175746f6672616d652f636f6d706f6e656e74732d736f636b65742d63616368653f6c6162656c3d7061636b6167697374253230737461626c65)[![Downloads](https://camo.githubusercontent.com/7ccac507ca58cb9cc7e25e4f734cc84a9771af3265cd28ade29ed73bbc6b0584/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646d2f6175746f6672616d652f636f6d706f6e656e74732d736f636b65742d63616368652e737667)](https://packagist.org/packages/autoframe/components-socket-cache)

*PHP socket client - cache server manager app*

**Examples**

```
use Autoframe\Components\SocketCache\Client\AfrClientStore;
use Autoframe\Components\SocketCache\App\AfrCacheApp;
use Autoframe\Components\SocketCache\Facade\AfrCache;
use Autoframe\Components\SocketCache\Facade\AfrRepositoryAutoSelector;

$oApp = AfrCacheApp::getInstance();

        `null`
        AfrCacheApp::getInstance()->setNullConfig(true);
        $oRepo = AfrCache::getManager()->store()

...

        `afrsock`
        if ($oApp->testSock()) {
            $oApp->setSockConfig([ // AfrCacheSocketConfig
                'driver' => 'afrsock',
                'iAutoShutdownServerAfterXSeconds' => 40,
                'bServerAutoPowerOnByConfigViaCliOnLocal' => true,
                'bObfuscateCommunicationBetweenClientServer' => false,
                'iServerMemoryMb' => 64,
                //     'socketPort' =>  rand(11222, 13222);
            ], $bDefault = true);
            $oRepo = AfrCache::getManager()->store();  //instanceof \Autoframe\Components\SocketCache\LaravelPort\Contracts\Cache\Repository
            $oRepo = AfrCache::getManager()->store('afrsock');
        }

...
        `array`
        $oApp = AfrCacheApp::getInstance()->setArrayConfig(
            $bSerialize = true,
            $bDefault = true
        );
        $oRepo = AfrCache::getManager()->store('array');

...
        `array`
        $oApp = AfrCacheApp::getInstance()->setArrayConfig(
            $bSerialize = true,
            $bDefault = true
        );
        $oRepo = AfrCache::getManager()->store('array');

...
        `file`
        $oApp = AfrCacheApp::getInstance()->setFileConfig(
            $bDefault = true,
            [ 'path' => __DIR__ . DIRECTORY_SEPARATOR . 'fileCache', ]
        );
        $oRepo = AfrCache::getManager()->store('file');
        //And...

        $oApp = AfrCacheApp::getInstance()->setFileConfig(
            $bDefault = false,
            [
                'driver' => 'file_nth_driver',
                'path' => __DIR__ . DIRECTORY_SEPARATOR . 'fileCache_other_dir',
            ]
        );
        $oRepo = AfrCache::getManager()->store('file_nth_driver');

...

        `memcached`
        if ($oApp->testMemcached()) {
            $oApp->setMemcachedConfig(
                $bDefault = false,
                [
                //'driver' => 'memcached',
                'servers' => $oApp->parseMemcachedServers('localhost:11211:100,...'),
                ]
            );
            $oRepo = AfrCache::getManager()->store('memcached');
        }

...

        `apc`  //apcu
        if ($oApp->testApc()) {
            $oApp->setApcConfig( $bDefault = false );
            $oRepo = AfrCache::getManager()->store('apc');
        }

```

---

```
`AfrRepositoryAutoSelector`

use Autoframe\Components\SocketCache\Client\AfrClientStore;
use Autoframe\Components\SocketCache\App\AfrCacheApp;
use Autoframe\Components\SocketCache\Facade\AfrCache;
use Autoframe\Components\SocketCache\Facade\AfrRepositoryAutoSelector;

        AfrRepositoryAutoSelector::setToUseRepositories(
            //HIGH_LOAD::SECONDARY_LOAD::FILESYSTEM::FILESYSTEM2::RAM::NONE
            AfrRepositoryAutoSelector::SECONDARY_LOAD,
            ['file'] //driver name
        );

        $sKeyName = $sKeyVal = 'sKeyName';
        $oRepo = AfrRepositoryAutoSelector::selectRepoByKeyNs(
            AfrRepositoryAutoSelector::prefixKeyForRepo(
                $sKeyName,
                AfrRepositoryAutoSelector::SECONDARY_LOAD
            )
        );
        $oRepo->set($sKeyName,$sKeyVal,60);
        // 1-9 priority or null for auto
        $oRepo = AfrRepositoryAutoSelector::selectRepoByKeyNs(AfrRepositoryAutoSelector::SECONDARY_LOAD.'\\1\\' . $sKeyName);
        $this->assertSame(true, $oRepo instanceof \Autoframe\Components\SocketCache\LaravelPort\Contracts\Cache\Repository);
        $this->assertSame($sKeyVal, $oRepo->get($sKeyName));
        $oRepo->clear();//flush
```

---

```
`AfrCache`

namespace Autoframe\Components\SocketCache\Facade;

use Autoframe\Components\SocketCache\App\AfrCacheApp;
use Autoframe\Components\SocketCache\LaravelPort\Cache\CacheManager;
use Autoframe\Components\SocketCache\AfrCacheManager;

/**
 * @method static \Autoframe\Components\SocketCache\LaravelPort\Cache\TaggedCache tags(array|mixed $names)
 * @method static \Autoframe\Components\SocketCache\LaravelPort\Cache\Lock lock(string $name, int $seconds = 0, mixed $owner = null)
 * @method static \Autoframe\Components\SocketCache\LaravelPort\Cache\Lock restoreLock(string $name, string $owner)
 * @method static \Autoframe\Components\SocketCache\LaravelPort\Contracts\Cache\Repository  store(string|null $name = null)
 * @method static \Autoframe\Components\SocketCache\LaravelPort\Contracts\Cache\Store getStore()
 * @method static bool add(string $key, $value, \DateTimeInterface|\DateInterval|int $ttl = null)
 * @method static bool flush()
 * @method static bool forever(string $key, $value)
 * @method static bool forget(string $key)
 * @method static bool has(string $key)
 * @method static bool missing(string $key)
 * @method static bool put(string $key, $value, \DateTimeInterface|\DateInterval|int $ttl = null)
 * @method static int|bool decrement(string $key, $value = 1)
 * @method static int|bool increment(string $key, $value = 1)
 * @method static mixed get(string $key, mixed $default = null)
 * @method static mixed pull(string $key, mixed $default = null)
 * @method static mixed remember(string $key, \DateTimeInterface|\DateInterval|int $ttl, \Closure $callback)
 * @method static mixed rememberForever(string $key, \Closure $callback)
 * @method static mixed sear(string $key, \Closure $callback)
 *
 * @see \Autoframe\Components\SocketCache\AfrCacheManager
 * @see \Autoframe\Components\SocketCache\LaravelPort\Cache\CacheManager
 * @see \Autoframe\Components\SocketCache\LaravelPort\Cache\Repository
 */
class AfrCache
{
    /**
     * @var CacheManager|AfrCacheManager
     */
    protected static CacheManager $instance;

    /**
     * @param CacheManager|AfrCacheManager $oCacheManager
     * @return CacheManager|AfrCacheManager
     */
    public static function setManager(CacheManager $oCacheManager): CacheManager
    {
        return static::$instance = $oCacheManager;
    }

    /**
     * @return CacheManager
     */
    public static function getManager(): CacheManager
    {
        if (empty(static::$instance)) {
            static::setManager(
                new AfrCacheManager(
                    AfrCacheApp::getInstance()
                )
            );
        }
        return static::$instance;
    }

    /**
     * @param $method
     * @param $args
     * @return mixed
     */
    public static function __callStatic($method, $args)
    {
        return static::getManager()->$method(...$args);
    }

}
```

---

```
namespace Autoframe\Components\SocketCache\LaravelPort\Contracts\Cache;

use Closure;

interface Repository
{
    // use Psr\SimpleCache\CacheInterface;
    /**
     * Fetches a value from the cache.
     *
     * @param string $key     The unique key of this item in the cache.
     * @param mixed  $default Default value to return if the key does not exist.
     *
     * @return mixed The value of the item from the cache, or $default in case of cache miss.
     *
     *   MUST be thrown if the $key string is not a legal value.
     */
    public function get($key, $default = null);

    /**
     * Persists data in the cache, uniquely referenced by a key with an optional expiration TTL time.
     *
     * @param string                 $key   The key of the item to store.
     * @param mixed                  $value The value of the item to store, must be serializable.
     * @param null|int|\DateInterval $ttl   Optional. The TTL value of this item. If no value is sent and
     *                                      the driver supports TTL then the library may set a default value
     *                                      for it or let the driver take care of that.
     *
     * @return bool True on success and false on failure.
     *
     *   MUST be thrown if the $key string is not a legal value.
     */
    public function set($key, $value, $ttl = null);

    /**
     * Delete an item from the cache by its unique key.
     *
     * @param string $key The unique cache key of the item to delete.
     *
     * @return bool True if the item was successfully removed. False if there was an error.
     *
     *   MUST be thrown if the $key string is not a legal value.
     */
    public function delete($key);

    /**
     * Wipes clean the entire cache's keys.
     *
     * @return bool True on success and false on failure.
     */
    public function clear();

    /**
     * Obtains multiple cache items by their unique keys.
     *
     * @param iterable $keys    A list of keys that can obtained in a single operation.
     * @param mixed    $default Default value to return for keys that do not exist.
     *
     * @return iterable A list of key => value pairs. Cache keys that do not exist or are stale will have $default as value.
     *
     *   MUST be thrown if $keys is neither an array nor a Traversable,
     *   or if any of the $keys are not a legal value.
     */
    public function getMultiple($keys, $default = null);

    /**
     * Persists a set of key => value pairs in the cache, with an optional TTL.
     *
     * @param iterable               $values A list of key => value pairs for a multiple-set operation.
     * @param null|int|\DateInterval $ttl    Optional. The TTL value of this item. If no value is sent and
     *                                       the driver supports TTL then the library may set a default value
     *                                       for it or let the driver take care of that.
     *
     * @return bool True on success and false on failure.
     *
     *   MUST be thrown if $values is neither an array nor a Traversable,
     *   or if any of the $values are not a legal value.
     */
    public function setMultiple($values, $ttl = null);

    /**
     * Deletes multiple cache items in a single operation.
     *
     * @param iterable $keys A list of string-based keys to be deleted.
     *
     * @return bool True if the items were successfully removed. False if there was an error.
     *
     *   MUST be thrown if $keys is neither an array nor a Traversable,
     *   or if any of the $keys are not a legal value.
     */
    public function deleteMultiple($keys);

    /**
     * Determines whether an item is present in the cache.
     *
     * NOTE: It is recommended that has() is only to be used for cache warming type purposes
     * and not to be used within your live applications operations for get/set, as this method
     * is subject to a race condition where your has() will return true and immediately after,
     * another script can remove it making the state of your app out of date.
     *
     * @param string $key The cache item key.
     *
     * @return bool
     *
     *   MUST be thrown if the $key string is not a legal value.
     */
    public function has($key);

    /**
     * Retrieve an item from the cache and delete it.
     *
     * @param  string  $key
     * @param  mixed  $default
     * @return mixed
     */
    public function pull($key, $default = null);

    /**
     * Store an item in the cache.
     *
     * @param  string  $key
     * @param  mixed  $value
     * @param  \DateTimeInterface|\DateInterval|int|null  $ttl
     * @return bool
     */
    public function put($key, $value, $ttl = null);

    /**
     * Store an item in the cache if the key does not exist.
     *
     * @param  string  $key
     * @param  mixed  $value
     * @param  \DateTimeInterface|\DateInterval|int|null  $ttl
     * @return bool
     */
    public function add($key, $value, $ttl = null);

    /**
     * Increment the value of an item in the cache.
     *
     * @param  string  $key
     * @param  mixed  $value
     * @return int|bool
     */
    public function increment($key, $value = 1);

    /**
     * Decrement the value of an item in the cache.
     *
     * @param  string  $key
     * @param  mixed  $value
     * @return int|bool
     */
    public function decrement($key, $value = 1);

    /**
     * Store an item in the cache indefinitely.
     *
     * @param  string  $key
     * @param  mixed  $value
     * @return bool
     */
    public function forever($key, $value);

    /**
     * Get an item from the cache, or execute the given Closure and store the result.
     *
     * @param  string  $key
     * @param  \DateTimeInterface|\DateInterval|int|null  $ttl
     * @param  \Closure  $callback
     * @return mixed
     */
    public function remember($key, $ttl, Closure $callback);

    /**
     * Get an item from the cache, or execute the given Closure and store the result forever.
     *
     * @param  string  $key
     * @param  \Closure  $callback
     * @return mixed
     */
    public function sear($key, Closure $callback);

    /**
     * Get an item from the cache, or execute the given Closure and store the result forever.
     *
     * @param  string  $key
     * @param  \Closure  $callback
     * @return mixed
     */
    public function rememberForever($key, Closure $callback);

    /**
     * Remove an item from the cache.
     *
     * @param  string  $key
     * @return bool
     */
    public function forget($key);

    /**
     * Get the cache store implementation.
     *
     * @return \Autoframe\Components\SocketCache\LaravelPort\Contracts\Cache\Store
     */
    public function getStore();
}

```

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity41

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

774d ago

### Community

Maintainers

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

---

Top Contributors

[![autoframe](https://avatars.githubusercontent.com/u/34517931?v=4)](https://github.com/autoframe "autoframe (3 commits)")

---

Tags

clientservercacheSocketmemcachedapccache managerfile system cachearray store

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/autoframe-components-socket-cache/health.svg)

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

###  Alternatives

[tedivm/stash

The place to keep your cache.

9824.8M124](/packages/tedivm-stash)[tedivm/stash-bundle

Incorporates the Stash caching library into Symfony.

841.4M16](/packages/tedivm-stash-bundle)[sabre/cache

Simple cache abstraction layer implementing PSR-16

541.2M3](/packages/sabre-cache)[kdyby/redis

Redis storage for Nette Framework

491.6M2](/packages/kdyby-redis)[ihor/cachalot

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

2528.1k](/packages/ihor-cachalot)[seregazhuk/react-memcached

Async Memcached client implementation, built on top of ReactPHP

261.4k1](/packages/seregazhuk-react-memcached)

PHPackages © 2026

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