https://github.com/akeb/framework-akeb-cache
composer project akeb/cache
https://github.com/akeb/framework-akeb-cache
composer php
Last synced: 4 months ago
JSON representation
composer project akeb/cache
- Host: GitHub
- URL: https://github.com/akeb/framework-akeb-cache
- Owner: AKEB
- License: apache-2.0
- Created: 2019-03-18T08:12:15.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2024-05-22T11:38:19.000Z (about 1 year ago)
- Last Synced: 2024-09-20T05:29:09.857Z (10 months ago)
- Topics: composer, php
- Language: PHP
- Homepage: https://packagist.org/packages/akeb/cache
- Size: 73.2 KB
- Stars: 1
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Cache
## Install
composer project akeb/cache
Composer config
```json
{
"require": {
"akeb/cache": "^1.1.6"
},
"repositories": [
{
"type": "vcs",
"url": "https://github.com/AKEB/Framework-AKEB-cache"
}
]
}
```or
```bash
composer require akeb/cache
```## If you use memcached
```php
global $CACHE_SERVERS;
$CACHE_SERVERS = [
'default' => ['host'=>'localhost', 'port' => 11211]
];require_once("../vendor/autoload.php");
```## If you use FileCache
```php
define('USE_FILE_CACHE', true); // Forcing the use of the file cachedefine('PATH_CACHE', '/opt/www/cache/'); // Cache file directory
require_once("../vendor/autoload.php");
```## Example use Cache
### Memcached cache
```php
global $CACHE_SERVERS;
$CACHE_SERVERS = [
'default' => ['host'=>'localhost', 'port' => 11211], // Description memcached servers
];
require_once("../vendor/autoload.php");$dateString = '';
$cache = new \Cache('testDate','default'); // Init Cache Object with name "testDate"
if (!$cache->isValid() && $cache->tryLock()) { // If cache not valid and we can lock cache
// Do something
$dateString = date("Y-m-d H:i:s", time());$cache->update($dateString,600); // Update cache data
$cache->freeLock(); // Free lock
} else { // Cache valid, or we can't lock cache
$dateString = $cache->get(); // get data from cache
}echo $dateString.PHP_EOL;
```### File cache
```php
define('PATH_CACHE', './tmp/'); // Cache file directoryrequire_once("../vendor/autoload.php");
$dateString = '';
$cache = new \Cache('testDate','default'); // Init Cache Object with name "testDate"
if (!$cache->isValid() && $cache->tryLock()) { // If cache not valid and we can lock cache
// Do something
$dateString = date("Y-m-d H:i:s", time());$cache->update($dateString,600); // Update cache data
$cache->freeLock(); // Free lock
} else { // Cache valid, or we can't lock cache
$dateString = $cache->get(); // get data from cache
}echo $dateString.PHP_EOL;
```See the `examples` folder for more details.
## Run Unit Tests
```bash
./dockerTest.sh
```