# Cache


The views use by default a cache system.

When loading a view, a file titled {fileDirectory}.tmp 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.


Is enabled

isEnabled(): bool

Returns true if the cache system is enabled, false otherwise.


Set status

setStatus([bool $enabled]): void

Sets the status of the cache system. true to enable it, false to disable it.


Get cache content

get(string $dir): string

Returns the content of the specified cache file.


That will return the content of the home cache file (home.tmp).

Create file

set(string $dir, string $content): string

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.

Create folder

mkdir(): bool

Makes the cache folder if it doesn't already exists.

This method returns true if the cache folder exists or has been created, false otherwise.



has(string $dir): bool

Returns true if the given cache key exists, false otherwise.


That will return true if the home cache file exists, false otherwise.

Get filename

getFilename(string $dir): string

Returns the absolute path of the given cache file.


That example should return something like /var/www/html/wolff/cache/home.tmp.


delete(string $dir): bool

Deletes the specified cache file.

This method returns true if the file has been successfully deleted, false otherwise.


That will delete the home cache file (cache/home.tmp).


clear([int $seconds]): void

Deletes the cache files.


That will delete all the cache files.

This method can take an optional parameter which is the minimum time (in seconds) that a file needs to have since its last creation/modification to be deleted.


That will delete any cache file that has been created/modified more than 60 seconds ago.

Documentation made with
Something is wrong in here? Make a issue/pull request on the repo.