Mecha CMS

Deep learning on using the API.

Class Cache

Author: Taufik Nurrohman · 36 Views

Tweet

Generate static data from a file.

Table of Content

Set 

Create a new cache file.

Cache::set($from, $content = null, $id = null);

Note: If $content is defined, then the cache content will be set based on that value instead of the $from file content.

Get 

Get the cache file.

Cache::get($from, $fail = false);

Example:

Get static data of path\to\file.php file:

$cache = Cache::get('path\to\file.php');

Example content of path\to\file.php file:

<?php

return (array) $_SERVER;

Reset 

Delete cache file.

Cache::reset($from = null);

Example:

Delete cache file of path\to\file.php:

Cache::reset('path\to\file.php');

Delete all cache:

Cache::reset();

Expire 

Check if cache file already expired.

Cache::expire($from, $id = null);

Example:

Check if cache file of path\to\file.php already expired:

if (Cache::expire('path\to\file.php')) {
    // expired!
}

ID 

Get cache ID.

Cache::id($from, $fail = -1);

Example:

Get cache ID of path\to\file.php:

$id = Cache::id('path\to\file.php');
$hash = md5(file_get_contents('path\to\file.php'));
if (is_string($id) && $id !== $hash || $id < File::T('path\to\file.php')) {
    // expired!
}

0 Comments

No comments yet.