Wolff\Core\Cache
The views use by default a cache system.
When loading a view, a file titled tmp_{fileDirectory}.php
will be created in the cache folder if it doesn't exists already.
So the view will be loader from that file and any change made to the original file will not be displayed until the cache file expires or is deleted manually.
You can perfectly refresh the cache deleting the cache folder content or the folder itself.
If you want to force a view to don't use the cache system, you can pass a false value to the render
method of the Wolff\Core\View
class as the third parameter.
View::render('home', $data, false);
That will force that view to don't use the cache system, keep in mind that the loading time could increase due to this.
The default life time for a cache file is One week.
isEnabled()
Returns true
if the cache system is enabled, false
otherwise.
Cache::isEnabled();
get(string $dir)
Returns the content of the specified cache file.
Cache::get('home');
That will return the content of the home cache file (tmp_home.php
).
set(string $dir, string $content)
Creates a cache file.
$file_content = '<h2>Hello</h2>';
Cache::set('home', $file_content);
The first parameter is the desired directory for the cache file, the second is the content that will be written into that file.
This method returns the path of the created cache file.
mkdir()
Makes the cache folder if it doesn't already exists.
Cache::mkdir();
has(string $dir)
Returns true
if the given cache key exists, false
otherwise.
Cache::has('home');
That will return true if the home cache file exists, false otherwise.
delete(string $dir)
Deletes the specified cache file.
Cache::delete('home');
That will delete the home cache file (cache/tmp_home.php
).
clear
Deletes all the cache file.
Cache::clear();
That will delete all the cache files.