{"id":25456439,"url":"https://github.com/autoframe/components-socket-cache","last_synced_at":"2025-05-16T18:11:14.494Z","repository":{"id":206699517,"uuid":"717488447","full_name":"autoframe/components-socket-cache","owner":"autoframe","description":"PHP client - cache server alternative for memcached / redis","archived":false,"fork":false,"pushed_at":"2024-04-04T18:50:51.000Z","size":82,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-18T01:40:22.838Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/autoframe.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-11-11T16:19:37.000Z","updated_at":"2024-04-04T18:49:51.000Z","dependencies_parsed_at":"2025-02-18T01:38:45.886Z","dependency_job_id":"ed2a2db5-01c1-4384-b3a9-17f866716f5c","html_url":"https://github.com/autoframe/components-socket-cache","commit_stats":null,"previous_names":["autoframe/components-socket-cache"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/autoframe%2Fcomponents-socket-cache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/autoframe%2Fcomponents-socket-cache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/autoframe%2Fcomponents-socket-cache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/autoframe%2Fcomponents-socket-cache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/autoframe","download_url":"https://codeload.github.com/autoframe/components-socket-cache/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254582907,"owners_count":22095518,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-02-18T01:38:35.461Z","updated_at":"2025-05-16T18:11:14.471Z","avatar_url":"https://github.com/autoframe.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Autoframe is a low level framework that is oriented on SOLID flexibility\n\n[![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)\n[![License: The 3-Clause BSD License](https://img.shields.io/github/license/autoframe/components-socket-cache)](https://opensource.org/license/bsd-3-clause/)\n![Packagist Version](https://img.shields.io/packagist/v/autoframe/components-socket-cache?label=packagist%20stable)\n[![Downloads](https://img.shields.io/packagist/dm/autoframe/components-socket-cache.svg)](https://packagist.org/packages/autoframe/components-socket-cache)\n\n*PHP socket client - cache server manager app*\n\n**Examples**\n\n```php\nuse Autoframe\\Components\\SocketCache\\Client\\AfrClientStore;\nuse Autoframe\\Components\\SocketCache\\App\\AfrCacheApp;\nuse Autoframe\\Components\\SocketCache\\Facade\\AfrCache;\nuse Autoframe\\Components\\SocketCache\\Facade\\AfrRepositoryAutoSelector;\n\n$oApp = AfrCacheApp::getInstance();\n\n        `null`\n        AfrCacheApp::getInstance()-\u003esetNullConfig(true);\n        $oRepo = AfrCache::getManager()-\u003estore()\n\n...\n\n        `afrsock`\n        if ($oApp-\u003etestSock()) {\n            $oApp-\u003esetSockConfig([ // AfrCacheSocketConfig\n                'driver' =\u003e 'afrsock',\n                'iAutoShutdownServerAfterXSeconds' =\u003e 40,\n                'bServerAutoPowerOnByConfigViaCliOnLocal' =\u003e true,\n                'bObfuscateCommunicationBetweenClientServer' =\u003e false,\n                'iServerMemoryMb' =\u003e 64,\n                //     'socketPort' =\u003e  rand(11222, 13222);\n            ], $bDefault = true);\n            $oRepo = AfrCache::getManager()-\u003estore();  //instanceof \\Autoframe\\Components\\SocketCache\\LaravelPort\\Contracts\\Cache\\Repository\n            $oRepo = AfrCache::getManager()-\u003estore('afrsock');\n        }\n\n...\n        `array`\n        $oApp = AfrCacheApp::getInstance()-\u003esetArrayConfig(\n            $bSerialize = true,\n            $bDefault = true\n        );\n        $oRepo = AfrCache::getManager()-\u003estore('array');\n\n...\n        `array`\n        $oApp = AfrCacheApp::getInstance()-\u003esetArrayConfig(\n            $bSerialize = true,\n            $bDefault = true\n        );\n        $oRepo = AfrCache::getManager()-\u003estore('array');\n\n...\n        `file`\n        $oApp = AfrCacheApp::getInstance()-\u003esetFileConfig(\n            $bDefault = true,\n            [ 'path' =\u003e __DIR__ . DIRECTORY_SEPARATOR . 'fileCache', ]\n        );\n        $oRepo = AfrCache::getManager()-\u003estore('file');\n        //And...\n        \n        $oApp = AfrCacheApp::getInstance()-\u003esetFileConfig(\n            $bDefault = false,\n            [\n                'driver' =\u003e 'file_nth_driver',\n                'path' =\u003e __DIR__ . DIRECTORY_SEPARATOR . 'fileCache_other_dir',\n            ]\n        );\n        $oRepo = AfrCache::getManager()-\u003estore('file_nth_driver');\n\n\n...\n\n        `memcached`\n        if ($oApp-\u003etestMemcached()) {\n            $oApp-\u003esetMemcachedConfig(\n                $bDefault = false,\n                [\n                //'driver' =\u003e 'memcached',\n                'servers' =\u003e $oApp-\u003eparseMemcachedServers('localhost:11211:100,...'),\n                ]\n            );\n            $oRepo = AfrCache::getManager()-\u003estore('memcached');\n        }\n\n\n\n...\n\n        `apc`  //apcu\n        if ($oApp-\u003etestApc()) {\n            $oApp-\u003esetApcConfig( $bDefault = false );\n            $oRepo = AfrCache::getManager()-\u003estore('apc');\n        }\n\n\n\n```\n\n---\n\n```php\n`AfrRepositoryAutoSelector`\n\n\nuse Autoframe\\Components\\SocketCache\\Client\\AfrClientStore;\nuse Autoframe\\Components\\SocketCache\\App\\AfrCacheApp;\nuse Autoframe\\Components\\SocketCache\\Facade\\AfrCache;\nuse Autoframe\\Components\\SocketCache\\Facade\\AfrRepositoryAutoSelector;\n\n\n        AfrRepositoryAutoSelector::setToUseRepositories(\n            //HIGH_LOAD::SECONDARY_LOAD::FILESYSTEM::FILESYSTEM2::RAM::NONE\n            AfrRepositoryAutoSelector::SECONDARY_LOAD, \n            ['file'] //driver name\n        );\n        \n        $sKeyName = $sKeyVal = 'sKeyName';\n        $oRepo = AfrRepositoryAutoSelector::selectRepoByKeyNs(\n            AfrRepositoryAutoSelector::prefixKeyForRepo(\n                $sKeyName,\n                AfrRepositoryAutoSelector::SECONDARY_LOAD\n            )\n        );\n        $oRepo-\u003eset($sKeyName,$sKeyVal,60);\n        // 1-9 priority or null for auto\n        $oRepo = AfrRepositoryAutoSelector::selectRepoByKeyNs(AfrRepositoryAutoSelector::SECONDARY_LOAD.'\\\\1\\\\' . $sKeyName);\n        $this-\u003eassertSame(true, $oRepo instanceof \\Autoframe\\Components\\SocketCache\\LaravelPort\\Contracts\\Cache\\Repository);\n        $this-\u003eassertSame($sKeyVal, $oRepo-\u003eget($sKeyName));\n        $oRepo-\u003eclear();//flush\n\n```\n\n---\n\n```php\n`AfrCache`\n\nnamespace Autoframe\\Components\\SocketCache\\Facade;\n\nuse Autoframe\\Components\\SocketCache\\App\\AfrCacheApp;\nuse Autoframe\\Components\\SocketCache\\LaravelPort\\Cache\\CacheManager;\nuse Autoframe\\Components\\SocketCache\\AfrCacheManager;\n\n/**\n * @method static \\Autoframe\\Components\\SocketCache\\LaravelPort\\Cache\\TaggedCache tags(array|mixed $names)\n * @method static \\Autoframe\\Components\\SocketCache\\LaravelPort\\Cache\\Lock lock(string $name, int $seconds = 0, mixed $owner = null)\n * @method static \\Autoframe\\Components\\SocketCache\\LaravelPort\\Cache\\Lock restoreLock(string $name, string $owner)\n * @method static \\Autoframe\\Components\\SocketCache\\LaravelPort\\Contracts\\Cache\\Repository  store(string|null $name = null)\n * @method static \\Autoframe\\Components\\SocketCache\\LaravelPort\\Contracts\\Cache\\Store getStore()\n * @method static bool add(string $key, $value, \\DateTimeInterface|\\DateInterval|int $ttl = null)\n * @method static bool flush()\n * @method static bool forever(string $key, $value)\n * @method static bool forget(string $key)\n * @method static bool has(string $key)\n * @method static bool missing(string $key)\n * @method static bool put(string $key, $value, \\DateTimeInterface|\\DateInterval|int $ttl = null)\n * @method static int|bool decrement(string $key, $value = 1)\n * @method static int|bool increment(string $key, $value = 1)\n * @method static mixed get(string $key, mixed $default = null)\n * @method static mixed pull(string $key, mixed $default = null)\n * @method static mixed remember(string $key, \\DateTimeInterface|\\DateInterval|int $ttl, \\Closure $callback)\n * @method static mixed rememberForever(string $key, \\Closure $callback)\n * @method static mixed sear(string $key, \\Closure $callback)\n *\n * @see \\Autoframe\\Components\\SocketCache\\AfrCacheManager\n * @see \\Autoframe\\Components\\SocketCache\\LaravelPort\\Cache\\CacheManager\n * @see \\Autoframe\\Components\\SocketCache\\LaravelPort\\Cache\\Repository\n */\nclass AfrCache\n{\n    /**\n     * @var CacheManager|AfrCacheManager\n     */\n    protected static CacheManager $instance;\n\n    /**\n     * @param CacheManager|AfrCacheManager $oCacheManager\n     * @return CacheManager|AfrCacheManager\n     */\n    public static function setManager(CacheManager $oCacheManager): CacheManager\n    {\n        return static::$instance = $oCacheManager;\n    }\n\n    /**\n     * @return CacheManager\n     */\n    public static function getManager(): CacheManager\n    {\n        if (empty(static::$instance)) {\n            static::setManager(\n                new AfrCacheManager(\n                    AfrCacheApp::getInstance()\n                )\n            );\n        }\n        return static::$instance;\n    }\n\n    /**\n     * @param $method\n     * @param $args\n     * @return mixed\n     */\n    public static function __callStatic($method, $args)\n    {\n        return static::getManager()-\u003e$method(...$args);\n    }\n\n}\n\n```\n\n---\n\n```php\n\nnamespace Autoframe\\Components\\SocketCache\\LaravelPort\\Contracts\\Cache;\n\nuse Closure;\n\ninterface Repository\n{\n    // use Psr\\SimpleCache\\CacheInterface;\n    /**\n     * Fetches a value from the cache.\n     *\n     * @param string $key     The unique key of this item in the cache.\n     * @param mixed  $default Default value to return if the key does not exist.\n     *\n     * @return mixed The value of the item from the cache, or $default in case of cache miss.\n     *\n     *   MUST be thrown if the $key string is not a legal value.\n     */\n    public function get($key, $default = null);\n\n    /**\n     * Persists data in the cache, uniquely referenced by a key with an optional expiration TTL time.\n     *\n     * @param string                 $key   The key of the item to store.\n     * @param mixed                  $value The value of the item to store, must be serializable.\n     * @param null|int|\\DateInterval $ttl   Optional. The TTL value of this item. If no value is sent and\n     *                                      the driver supports TTL then the library may set a default value\n     *                                      for it or let the driver take care of that.\n     *\n     * @return bool True on success and false on failure.\n     *\n     *   MUST be thrown if the $key string is not a legal value.\n     */\n    public function set($key, $value, $ttl = null);\n\n    /**\n     * Delete an item from the cache by its unique key.\n     *\n     * @param string $key The unique cache key of the item to delete.\n     *\n     * @return bool True if the item was successfully removed. False if there was an error.\n     *\n     *   MUST be thrown if the $key string is not a legal value.\n     */\n    public function delete($key);\n\n    /**\n     * Wipes clean the entire cache's keys.\n     *\n     * @return bool True on success and false on failure.\n     */\n    public function clear();\n\n    /**\n     * Obtains multiple cache items by their unique keys.\n     *\n     * @param iterable $keys    A list of keys that can obtained in a single operation.\n     * @param mixed    $default Default value to return for keys that do not exist.\n     *\n     * @return iterable A list of key =\u003e value pairs. Cache keys that do not exist or are stale will have $default as value.\n     *\n     *   MUST be thrown if $keys is neither an array nor a Traversable,\n     *   or if any of the $keys are not a legal value.\n     */\n    public function getMultiple($keys, $default = null);\n\n    /**\n     * Persists a set of key =\u003e value pairs in the cache, with an optional TTL.\n     *\n     * @param iterable               $values A list of key =\u003e value pairs for a multiple-set operation.\n     * @param null|int|\\DateInterval $ttl    Optional. The TTL value of this item. If no value is sent and\n     *                                       the driver supports TTL then the library may set a default value\n     *                                       for it or let the driver take care of that.\n     *\n     * @return bool True on success and false on failure.\n     *\n     *   MUST be thrown if $values is neither an array nor a Traversable,\n     *   or if any of the $values are not a legal value.\n     */\n    public function setMultiple($values, $ttl = null);\n\n    /**\n     * Deletes multiple cache items in a single operation.\n     *\n     * @param iterable $keys A list of string-based keys to be deleted.\n     *\n     * @return bool True if the items were successfully removed. False if there was an error.\n     *\n     *   MUST be thrown if $keys is neither an array nor a Traversable,\n     *   or if any of the $keys are not a legal value.\n     */\n    public function deleteMultiple($keys);\n\n    /**\n     * Determines whether an item is present in the cache.\n     *\n     * NOTE: It is recommended that has() is only to be used for cache warming type purposes\n     * and not to be used within your live applications operations for get/set, as this method\n     * is subject to a race condition where your has() will return true and immediately after,\n     * another script can remove it making the state of your app out of date.\n     *\n     * @param string $key The cache item key.\n     *\n     * @return bool\n     *\n     *   MUST be thrown if the $key string is not a legal value.\n     */\n    public function has($key);\n    \n    /**\n     * Retrieve an item from the cache and delete it.\n     *\n     * @param  string  $key\n     * @param  mixed  $default\n     * @return mixed\n     */\n    public function pull($key, $default = null);\n\n    /**\n     * Store an item in the cache.\n     *\n     * @param  string  $key\n     * @param  mixed  $value\n     * @param  \\DateTimeInterface|\\DateInterval|int|null  $ttl\n     * @return bool\n     */\n    public function put($key, $value, $ttl = null);\n\n    /**\n     * Store an item in the cache if the key does not exist.\n     *\n     * @param  string  $key\n     * @param  mixed  $value\n     * @param  \\DateTimeInterface|\\DateInterval|int|null  $ttl\n     * @return bool\n     */\n    public function add($key, $value, $ttl = null);\n\n    /**\n     * Increment the value of an item in the cache.\n     *\n     * @param  string  $key\n     * @param  mixed  $value\n     * @return int|bool\n     */\n    public function increment($key, $value = 1);\n\n    /**\n     * Decrement the value of an item in the cache.\n     *\n     * @param  string  $key\n     * @param  mixed  $value\n     * @return int|bool\n     */\n    public function decrement($key, $value = 1);\n\n    /**\n     * Store an item in the cache indefinitely.\n     *\n     * @param  string  $key\n     * @param  mixed  $value\n     * @return bool\n     */\n    public function forever($key, $value);\n\n    /**\n     * Get an item from the cache, or execute the given Closure and store the result.\n     *\n     * @param  string  $key\n     * @param  \\DateTimeInterface|\\DateInterval|int|null  $ttl\n     * @param  \\Closure  $callback\n     * @return mixed\n     */\n    public function remember($key, $ttl, Closure $callback);\n\n    /**\n     * Get an item from the cache, or execute the given Closure and store the result forever.\n     *\n     * @param  string  $key\n     * @param  \\Closure  $callback\n     * @return mixed\n     */\n    public function sear($key, Closure $callback);\n\n    /**\n     * Get an item from the cache, or execute the given Closure and store the result forever.\n     *\n     * @param  string  $key\n     * @param  \\Closure  $callback\n     * @return mixed\n     */\n    public function rememberForever($key, Closure $callback);\n\n    /**\n     * Remove an item from the cache.\n     *\n     * @param  string  $key\n     * @return bool\n     */\n    public function forget($key);\n\n    /**\n     * Get the cache store implementation.\n     *\n     * @return \\Autoframe\\Components\\SocketCache\\LaravelPort\\Contracts\\Cache\\Store\n     */\n    public function getStore();\n}\n\n\n\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fautoframe%2Fcomponents-socket-cache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fautoframe%2Fcomponents-socket-cache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fautoframe%2Fcomponents-socket-cache/lists"}