{"id":25201976,"url":"https://github.com/alexsandrov16/cache","last_synced_at":"2025-05-12T18:03:30.443Z","repository":{"id":253865446,"uuid":"842305306","full_name":"alexsandrov16/cache","owner":"alexsandrov16","description":"A simple cache library.","archived":false,"fork":false,"pushed_at":"2025-03-21T15:41:31.000Z","size":44,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-01T01:28:03.864Z","etag":null,"topics":["apcu","cache","cache-file","mk4u","php","php-cache"],"latest_commit_sha":null,"homepage":"","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/alexsandrov16.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":"2024-08-14T04:46:30.000Z","updated_at":"2025-03-21T15:41:35.000Z","dependencies_parsed_at":"2024-11-27T16:22:22.264Z","dependency_job_id":"c367218b-7426-450c-989e-74f40f709187","html_url":"https://github.com/alexsandrov16/cache","commit_stats":null,"previous_names":["alexsandrov16/cache"],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexsandrov16%2Fcache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexsandrov16%2Fcache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexsandrov16%2Fcache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexsandrov16%2Fcache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alexsandrov16","download_url":"https://codeload.github.com/alexsandrov16/cache/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253795097,"owners_count":21965485,"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":["apcu","cache","cache-file","mk4u","php","php-cache"],"created_at":"2025-02-10T06:16:22.629Z","updated_at":"2025-05-12T18:03:30.399Z","avatar_url":"https://github.com/alexsandrov16.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Mk4U\\Cache\n\n![GitHub Release](https://img.shields.io/github/v/release/alexsandrov16/cache?include_prereleases\u0026style=flat-square\u0026color=blue)\n![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/alexsandrov16/cache?style=flat-square)\n![GitHub License](https://img.shields.io/github/license/alexsandrov16/cache?style=flat-square)\n\nA simple and flexible cache system for PHP.\n\n## Features\n* Support for multiple cache drivers (APCu and files)\n* Implementation of the `Psr\\SimpleCache\\CacheInterface` interface.\n* Efficient storage and retrieval of data.\n\n\u003e [!IMPORTANT]\n\u003e The file driver `Mk4U\\Cache\\Drivers\\File` is suitable for storing small amounts of data in cache. However, as the number of records increases, performance may be affected due to the latency of disk I/O operations.\n\u003e \n\u003e For applications that require storing large volumes of data or high performance, it is recommended to consider using in-memory cache drivers, such as APCu, \u003c!--Redis, or Memcached,--\u003e which are designed to handle large amounts of data more efficiently.\n\n## Requirements\n* PHP 8.2 or higher\n* APCu extension (optional)\n\n## Installation\n```bash\ncomposer require mk4u/cache\n```\n\n## Usage.\n\n### Configuration\nTo use the library, you must first create an instance of the cache driver you want to use. The library includes a `Mk4U\\Cache\\CacheFactory` that makes it easy to create instances of the cache drivers.\n\n\u003e [!TIP]\n\u003e If no parameters are passed to the `Mk4U\\Cache\\CacheFactory::create()`, an object of type `Mk4U\\Cache\\Drivers\\File` will be created by default.\n\n\u003e [!NOTE]\n\u003e By default the `Mk4U\\Cache\\Drivers\\File` object sets the following configuration parameters:\n\u003e\n\u003e ```php\n\u003e [\n\u003e    //extension of cache files\n\u003e    'ext' =\u003e'cache',\n\u003e    //directory where the cache will be stored, if it does not exist create it.\n\u003e    'dir' =\u003e '/cache',\n\u003e    //cache lifetime in seconds (default 5 minutes.)\n\u003e    'ttl' =\u003e 300\n\u003e ]\n\u003e ```\n\n#### Example of use with the `Mk4U\\Cache\\Drivers\\File` driver\n```php\nrequire 'vendor/autoload.php';\n\n// Cache driver configuration\n$config = [\n    'ext' =\u003e 'txt', // Extension of cache files.\n    'dir' =\u003e '/cache', // Directory where the cache will be stored\n    'ttl' =\u003e 3600 // Cache lifetime in seconds.\n];\n\n// Create an instance of the file cache driver.\n$cache = Mk4U\\Cache\\CacheFactory::create('file', $config);\n```\n\u003e [!IMPORTANT]\n\u003e Make sure you set the necessary permissions for the creation of directories and cache files. \n\n#### Example of use with `Mk4U\\Cache\\Drivers\\Apcu` driver\n```php\nrequire 'vendor/autoload.php';\n\n// Cache driver configuration\n$config = [\n    'ttl' =\u003e 3600 // cache lifetime in seconds (default 5 minutes.)\n];\n\n// Create an instance of the APCu cache driver.\n$cache = Mk4U\\Cache\\CacheFactory::create('apcu', $config);\n```\n`Mk4U\\Cache\\Drivers\\Apcu` has only one configurable parameter and it is `ttl`, by default its value is 300 seconds (5 minutes).\n\n\n### Available methods\nThe cache class implements the following methods of the CacheInterface interface:\n\n* `get(string $key, mixed $default = null): mixed`\n* `set(string $key, mixed $value, null|int|DateInterval $ttl = null): bool`\n* `delete(string $key): bool`\n* `clear(): bool`\n* `getMultiple(iterable $keys, mixed $default = null): iterable`\n* `setMultiple(iterable $values, null|int|DateInterval $ttl = null): bool`\n* `deleteMultiple(iterable $keys): bool`\n* `has(string $key): bool`\n\n#### Example of use of the methods\n\n##### Storing a value in the cache\n```php\n// Store the value in the cache\n$cache-\u003eset('my_key', 'Hello, World!');\n```\n\n##### Retrieve a value from the cache\n```php\n// Retrieve cache value\n$cachedValue = $cache-\u003eget('my_key', 'Default value');\n\necho $cachedValue; // Print: Hello, World!\n```\n\n##### Remove a value from the cache\n```php\n// Delete the value from the cache\n$cache-\u003edelete('my_key');\n```\n\n##### Checks if a value exists in the cache by its key\n```php\n// checks if a value exists\nreturn $cache-\u003ehas('my_key'); //false\n```\n\n##### Clear the entire cache\n```php\n// Clear the entire cache\n$cache-\u003eclear();\n```\n\n###### Handling multiple values\n\nYou can store, retrieve and delete multiple values from the cache using the setMultiple, getMultiple and deleteMultiple methods.\n\n###### Storing multiple values\n```php\n$values = [\n    'key1' =\u003e 'Value 1',\n    'key2' =\u003e 'Value 2'\n];\n\n$cache-\u003esetMultiple($values);\n```\n\n###### Retrieve multiple values\n```php\n$keys = ['key1', 'key2'];\n$cachedValues = $cache-\u003egetMultiple($keys, 'Default value');\n\nprint_r($cachedValues); // Print stored values\n```\n\n###### Delete multiple values\n```php\n$keysToDelete = ['key1', 'key2'];\n$cache-\u003edeleteMultiple($keysToDelete);\n```\n\n### Exceptions\nThe library throws the following exceptions:\n* `Mk4U\\Cache\\Exceptions\\CacheException`: for cache related errors.\n* `Mk4U\\Cache\\Exceptions\\InvalidArgumentException`: For invalid arguments.\n\n## Contributions\nContributions are welcome. If you wish to contribute, please open an issue or a pull request in the repository.\n\n## License\nThis project is licensed under the [MIT License](https://github.com/alexsandrov16/cache?tab=MIT-1-ov-file).\n\n## Contact\nIf you have any questions or comments, feel free to contact me at [Telegram](http://t.me/alexsadrov16).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexsandrov16%2Fcache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falexsandrov16%2Fcache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexsandrov16%2Fcache/lists"}