first commit.
This commit is contained in:
+60
@@ -0,0 +1,60 @@
|
||||
<?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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user