61 lines
1.6 KiB
PHP
Executable File
61 lines
1.6 KiB
PHP
Executable File
<?php
|
|
|
|
namespace Libs;
|
|
|
|
/**
|
|
* DuckBrain - Microframework
|
|
*
|
|
* APCache is a simple library that makes use of APC cache.
|
|
* Data is stored in memory and does not disappear until
|
|
* it expires or is explicitly deleted.
|
|
*
|
|
* @author: KJ
|
|
* @web: https://kj2.me
|
|
* @license: MIT
|
|
*/
|
|
class APCache
|
|
{
|
|
/**
|
|
* Get an item from the cache.
|
|
*
|
|
* @param string $key
|
|
* The key to retrieve.
|
|
* @return mixed
|
|
* The stored variable or an array of variables on success; FALSE on failure.
|
|
*/
|
|
public static function get(string $key): mixed
|
|
{
|
|
return apcu_fetch($key);
|
|
}
|
|
|
|
/**
|
|
* Stores or overwrites a key in the cache.
|
|
*
|
|
* @param string $key
|
|
* The key to store.
|
|
* @param mixed $data
|
|
* The variable to store under the key.
|
|
* @param int $expire
|
|
* Expiration time for the key in seconds.
|
|
* @return bool | array
|
|
* Returns TRUE on success or FALSE on failure. An array of error keys on failure.
|
|
*/
|
|
public static function save(string $key, mixed $data, int $expire = 0): bool|array
|
|
{
|
|
return apcu_store($key, $data, $expire);
|
|
}
|
|
|
|
/**
|
|
* Deletes an item from the cache.
|
|
*
|
|
* @param string $key
|
|
* The key to delete.
|
|
* @return boolean | array
|
|
* Returns TRUE on success or FALSE on failure. An array of error keys on failure.
|
|
*/
|
|
public static function delete(string $key): bool|array
|
|
{
|
|
return apcu_delete($key);
|
|
}
|
|
}
|