aportela / simple-fs-cache
Custom php filesystem cache
Installs: 37
Dependents: 5
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/aportela/simple-fs-cache
Requires
- php: >=8.4
- psr/log: ^3.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.88
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^10.5
README
Custom php filesystem cache
Requirements
- mininum php version 8.4
Install (composer) dependencies:
composer require aportela/simple-fs-cache
Code example:
<?php require "vendor/autoload.php"; $logger = new \Psr\Log\NullLogger(""); $cachePath = dirname(__FILE__) . DIRECTORY_SEPARATOR . "cache" $cache = new \aportela\SimpleFSCache\Cache(parent::$logger, \aportela\SimpleFSCache\CacheFormat::TXT, $cachePath, false); $data = "this is the data to store in cache"; // you can use another hash algorithm if you don't trust that MD5 value is unique $cacheUniqueIdentifier = md5($data); if ($cache->save($cacheUniqueIdentifier, $data)) { $cachedData = $cache->get(); if ($cachedData !== false) { echo "Cache load sucessfully, contents: {$cachedData}" . PHP_EOL; } $cache->remove($cacheUniqueIdentifier); } else { echo "Error saving cache" . PHP_EOL; }