{"id":13624006,"url":"https://github.com/apix/cache","last_synced_at":"2025-04-05T06:06:05.251Z","repository":{"id":55623251,"uuid":"7551230","full_name":"apix/cache","owner":"apix","description":"A thin PSR-6 cache wrapper with a generic interface to various caching backends emphasising cache tagging and indexing.","archived":false,"fork":false,"pushed_at":"2022-07-26T12:14:20.000Z","size":405,"stargazers_count":116,"open_issues_count":4,"forks_count":27,"subscribers_count":11,"default_branch":"master","last_synced_at":"2025-04-01T06:37:34.300Z","etag":null,"topics":["apc","apcu","apix","apix-cache","cache-backend","igbinary","json","mariadb","memcached","mongodb","msgpack","mysql","oracle","pdo","pgsql","psr-6","psr-cache","redis","sqlite","tagging"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/apix.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":".github/CONTRIBUTING.md","funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-01-11T00:09:16.000Z","updated_at":"2025-03-15T20:58:35.000Z","dependencies_parsed_at":"2022-08-15T04:40:54.754Z","dependency_job_id":null,"html_url":"https://github.com/apix/cache","commit_stats":null,"previous_names":[],"tags_count":23,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apix%2Fcache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apix%2Fcache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apix%2Fcache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apix%2Fcache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/apix","download_url":"https://codeload.github.com/apix/cache/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247294537,"owners_count":20915340,"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":["apc","apcu","apix","apix-cache","cache-backend","igbinary","json","mariadb","memcached","mongodb","msgpack","mysql","oracle","pdo","pgsql","psr-6","psr-cache","redis","sqlite","tagging"],"created_at":"2024-08-01T21:01:37.779Z","updated_at":"2025-04-05T06:06:05.218Z","avatar_url":"https://github.com/apix.png","language":"PHP","readme":"Apix Cache, cache-tagging for PHP\n[![Build Status](https://travis-ci.org/apix/cache.svg?branch=master)](https://travis-ci.org/apix/cache)\n=================================\n[![Latest Stable Version](https://poser.pugx.org/apix/cache/v/stable.svg)](https://packagist.org/packages/apix/cache)\n[![Total Downloads](https://poser.pugx.org/apix/cache/downloads)](https://packagist.org/packages/apix/cache)\n[![Build Status](https://scrutinizer-ci.com/g/frqnck/apix-cache/badges/build.png?b=master)](https://scrutinizer-ci.com/g/frqnck/apix-cache/build-status/master)\n[![Code Quality](https://scrutinizer-ci.com/g/frqnck/apix-cache/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/frqnck/apix-cache/?branch=master)\n[![Code Coverage](https://scrutinizer-ci.com/g/frqnck/apix-cache/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/frqnck/apix-cache/?branch=master)\n[![License](https://poser.pugx.org/apix/cache/license.svg)](https://packagist.org/packages/apix/cache)\n\nApix Cache is a generic and thin cache wrapper with a PSR-6 interface to various caching backends and emphasising cache **tagging** and **indexing**.\n\n\u003e Cache-tagging allows to find/update all data items with one or more given tags. Providing, for instance, a batch delete of all obsolete entries matching a speficic tag such as a version string.\n\n* Fully **unit-tested** and compliant with PSR-1, PSR-2, PSR-4 and **PSR-6** (Cache).\n* [Continuously integrated](https://travis-ci.org/apix/cache)\n  * against **PHP** ~~5.3~~, **5.4**, **5.5**, **5.6**, **7.0**, **7.1**, **7.2**, **7.3** ~~and HHVM~~,\n  * and against `APC`, `APCu`, `Redis`, `MongoDB`, `Sqlite`, `MySQL`, `PgSQL` and `Memcached`, ...\n  * supports a range of serializers: `igBinary`, `msgpack`, `json`, `php`, ...\n* Extendable, additional extensions are available:\n   * **[apix/simple-cache](//github.com/apix/simple-cache)** provides a SimpleCache (PSR-16) interface.\n   * More contributions will be linked here.\n* Available as a [Composer](https://packagist.org/packages/apix/cache) ~~and as a [PEAR](http://pear.ouarz.net)~~ package.\n\n⇄ *[Pull requests](//github.com/frqnck/apix-cache/blob/master/.github/CONTRIBUTING.md)* and ★ *Stars* are always welcome. For bugs and feature request, please [create an issue](//github.com/frqnck/apix-cache/issues/new).\n\n---\n\nCache backends\n--------------\nCurrently, the following cache store are supplied:\n\n* **[`APCu`](http://php.net/apcu)** and **[APC](http://php.net/apc)** *with tagging support*,\n* **[Redis](#redis-specific)** using the [`PhpRedis`](https://github.com/phpredis/phpredis) extension *with tagging support*,\n* **[MongoDB](#mongodb-specific)** using either the new [`mongodb`](http://php.net/mongodb) or the legacy [`mongo`](http://php.net/mongo) extension *with tagging support*,\n* **[Memcached](#memcached-specific)** using the [`Memcached`](http://php.net/book.memcached.php) extension *with indexing, tagging and namespacing support*,\n* and relational databases using **[PDO](#pdo-specific)** *with tagging support*:\n  * Dedicated drivers for **[SQLite](http://www.sqlite.org)**, **[PostgreSQL](http://www.postgresql.org)** and **[MySQL](http://www.mysql.com)** (also works with Amazon Aurora, MariaDB and Percona),\n  * A generic **[Sql1999](https://en.wikipedia.org/wiki/SQL:1999)** driver for [4D](http://www.4d.com/), [Cubrid](http://www.cubrid.org), [SQL Server](http://www.microsoft.com/sqlserver), [Sybase](http://www.sybase.com), [Firebird](http://www.firebirdsql.org), [ODBC](https://en.wikipedia.org/wiki/Open_Database_Connectivity), [Interbase](http://www.embarcadero.com/products/interbase), [IBM DB2](www.ibm.com/software/data/db2/), [IDS](http://www-01.ibm.com/software/data/informix/), [Oracle](http://www.oracle.com/database)...\n* **[Directory](#filesystem-specific)** and **[Files](#filesystem-specific)** based *with tagging support*,\n* **Runtime**, in-memory array storage.\n\nFactory usage (PSR-Cache wrapper)\n-------------\n\n```php\n  use Apix\\Cache;\n\n  $backend = new \\Redis();\n  #$backend = new \\PDO('sqlite:...');    // Any supported client object e.g. Memcached, MongoClient, ...\n  #$backend = new Cache\\Files($options); // or one that implements Apix\\Cache\\Adapter\n  #$backend = 'apcu';                    // or an adapter name (string) e.g. \"APC\", \"Runtime\"\n  #$backend = new MyArrayObject();       // or even a plain array() or \\ArrayObject.\n\n  $cache = Cache\\Factory::getPool($backend);             // without tagging support\n  #$cache = Cache\\Factory::getTaggablePool($backend);    // with tagging\n  \n  $item = $cache-\u003egetItem('wibble_id');\n  \n  if ( !$cache-\u003eisHit() ) {\n    $data = compute_expensive_stuff();\n    $item-\u003eset($data);\n    $cache-\u003esave($item);\n  }\n\n  return $item-\u003eget();\n```\n\nBasic usage (Apix native)\n-----------\n\n```php\n  use Apix\\Cache;\n\n  $cache = new Cache\\Apcu;\n\n  // try to retrieve 'wibble_id' from the cache\n  if ( !$data = $cache-\u003eload('wibble_id') ) {\n    \n    // otherwise, get some data from the origin\n    // example of arbitrary mixed data\n    $data = array('foo' =\u003e 'bar');\n\n    // and save it to the cache\n    $cache-\u003esave($data, 'wibble_id');\n  }\n```\nYou can also use the folowing in your use cases: \n```php\n  // save $data to the cache as 'wobble_id',\n  // tagging it along the way as 'baz' and 'flob',\n  // and set the ttl to 300 seconds (5 minutes)\n  $cache-\u003esave($data, 'wobble_id', array('baz', 'flob'), 300);\n\n  // retrieve all the cache ids under the tag 'baz'\n  $ids = $cache-\u003eloadTag('baz');\n\n  // clear out all items with a 'baz' tag\n  $cache-\u003eclean('baz');\n\n  // remove the named item\n  $cache-\u003edelete('wibble_id');\n\n  // flush out the cache (of all -your- stored items)\n  $cache-\u003eflush();\n```\n\nAdvanced usage\n--------------\n### Options shared by all the backends\n```php\n  use Apix\\Cache;\n  \n  // default options\n  $options = array(\n      'prefix_key'  =\u003e 'apix-cache-key:', // prefix cache keys\n      'prefix_tag'  =\u003e 'apix-cache-tag:', // prefix cache tags\n      'tag_enable'  =\u003e true               // wether to enable tags support\n  );\n\n  // start APCu as a local cache\n  $local_cache = new Cache\\Apcu($options);\n```\n\n### Redis specific\n```php\n  // additional (default) options\n  $options['atomicity']  = false;   // false is faster, true is guaranteed\n  $options['serializer'] = 'php';   // null, php, igbinary, json and msgpack\n\n  $redis_client = new \\Redis;       // instantiate phpredis*\n  $distributed_cache = new Cache\\Redis($redis_client, $options);\n```\n\\* see [PhpRedis](https://github.com/nicolasff/phpredis) for instantiation usage.\n\n### Memcached specific\n```php\n  // additional (default) options, specific to Memcached\n  $options['prefix_key'] = 'key_';  // prefix cache keys\n  $options['prefix_tag'] = 'tag_';  // prefix cache tags\n  $options['prefix_idx'] = 'idx_';  // prefix cache indexes\n  $options['prefix_nsp'] = 'nsp_';  // prefix cache namespaces\n  $options['serializer'] = 'auto';  // auto, igbinary, msgpack, php, json and json_array.\n\n  $memcached  = new \\Memcached;     // a Memcached*** instance\n  $shared_cache = new Cache\\Memcached($memcached, $options);\n```\n\nThe serialzer `auto` (default) is `igBinary` if available, then `msgpack` if available, then `php` otherwise.\n\n\\*\\*\\* see [Memcached](http://php.net/manual/en/book.memcached.php) for instantiation details.\n\n### MongoDB specific \n```php\n  // additional (default) options\n  $options['object_serializer'] = 'php';  // null, json, php, igBinary\n  $options['db_name'] = 'apix';           // name of the mongo db\n  $options['collection_name'] = 'cache';  // name of the mongo collection\n\n  $mongo  = new \\MongoDB\\Client;          // MongoDB native driver\n  #$mongo  = new \\MongoClient;            // or MongoDB legacy driver\n  $cache = new Cache\\Mongo($mongo, $options);\n```\n\n### PDO specific\n```php\n  // additional (default) options, specific to the PDO backends\n  $options['db_table']   = 'cache';       // table to hold the cache\n  $options['serializer'] = 'php';         // null, php, igbinary, json and msgpack\n  $options['preflight']  = true;          // wether to preflight the DB\n  $options['timestamp']  = 'Y-m-d H:i:s'; // the timestamp DB format\n\n  // with SQLITE\n  $dbh = new \\PDO('sqlite:/tmp/apix_tests.sqlite3');\n  $relational_cache = new Cache\\Pdo\\Sqlite($dbh, $options);\n\n  // with MYSQL, MariaDB and Percona\n  $dbh = new \\PDO('mysql:host=xxx;port=xxx;dbname=xxx', 'user', 'pass');\n  $mysql_cache = new Cache\\Pdo\\Mysql($dbh, $options);\n\n  // with PGSQL\n  $dbh = new \\PDO('pgsql:dbname=xxx;host=xxx', 'xxx', 'xxx');\n  $postgres_cache = new Cache\\Pdo\\Pgsql($dbh, $options);\n\n  // with a SQL:1999 compliant DB, e.g. Oracle\n  $dbh = new \\PDO('oci:dbname=xxx', 'xxx', 'xxx');\n  $sql1999_cache = new Cache\\Pdo\\Sql1999($dbh, $options);\n```\nThe `preflight` option will create on-the-fly the required tables if these are mssing.\nOnce these tables exist, set `preflight` to `false` in order to avoid the extraneous checks. \n\n### Filesystem specific\n\n```php\n  // additional (default) options\n  $options['directory'] = sys_get_temp_dir() . '/apix-cache'; // Directory where the cache is created\n  $options['locking'] = true;                                 // File locking (recommended)\n  \n  $files_cache = new Cache\\Files($options);\n  // or\n  $directory_cache = new Cache\\Directory($options);  \n```\n\n  - **Files**: the cache metadata (expiration time and tags) are stored in the cache file directly.\n  - **Directory**: the metadata are stored separately from the cached data. \n\nInstallation\n------------------------\n\nThis project adheres to [Semantic Versioning](http://semver.org/) and can be installed using composer:  \n\n    $ composer require apix/cache:^1.3\n\nAll notable changes to this project are documented in its [CHANGELOG](CHANGELOG.md).\n\nLicense\n-------\nThis work is licensed under the New BSD license -- see the [LICENSE](LICENSE.txt) for the full details.\u003cbr\u003eCopyright (c) 2010-2016 Franck Cassedanne\n","funding_links":[],"categories":["目录","Table of Contents","PHP"],"sub_categories":["缓存和锁定 Caching and Locking","Caching and Locking","Caching"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fapix%2Fcache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fapix%2Fcache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fapix%2Fcache/lists"}