> For the complete documentation index, see [llms.txt](https://docs.cmsfullform.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.cmsfullform.com/documents/drivers/cache/files-cache.md).

# Files Cache

The `FilesCache.php` file is a concrete implementation of the abstract `Cache` class. It provides methods to store, retrieve, and manage cached data using the file system. Below is an explanation of the code in `FilesCache.php`.

It provides methods to store, retrieve, and manage cached data using the file system. Below is an explanation of each method in `FilesCache.php` along with examples:

## `set()`

```php
function set($key, $value, $ttl = 3600)
```

Stores a value in the cache with a specified time-to-live (TTL). The value is serialized and saved in a file identified by the MD5 hash of the key.

* `$key` – The key under which to store the value.
* `$value` – The value to store.
* `$ttl` – Time-to-live in seconds.
* `$ttl`  - `true` if the value was successfully set, `false` otherwise

Example:

```php
<?php
$cache = new FilesCache()
$cache->set('php_fast', ['name' => 'PHPFast Framework', 'version' => '1.0'], 600);
```

## `get()`

```php
function get($key)
```

Retrieves a cached value using its key. If the key exists, the stored data is unserialized and returned; otherwise, `null` is returned.

* `$key` – The key of the value to retrieve.
* `return` – The value stored in the cache or null if not found

Example:

```php
<?php
$phpFast = $cache->get('php_fast');
if ($phpFast !== null) {
    echo "Data loaded from cache.";
} else {
    echo "Data not found in cache.";
}
```

## `delete()`

```php
function delete($key)
```

Removes a cached value based on the provided key. If the key exists, the corresponding data is deleted from the cache.

* `$key` – The key of the value to delete.
* `return` – `true` if the value was successfully deleted, `false` otherwise.

Example:

```php
<?php
$cache->delete('php_fast');
```

## `has()`

```php
function has($key)
```

Checks whether a specific key exists in the cache. Returns `true` if the key is found, otherwise returns `false`.

* `$key` – The key to check for existence.
* `return` – `true` if key exists, `false` otherwise.

Example:

```php
<?php
if ($cache->has('php_fast')) {
    echo "Cache exists for php_fast.";
} else {
    echo "No cache for php_fast.";
}
```

## `clear()`

```php
function clear()
```

Clears all cached data, effectively resetting the cache system by removing all stored keys and their values.

* `return` – `true` if the cache was successfully cleared, `false` otherwise

Example:

```php
<?php
$cache->clear();
```

{% hint style="success" %}
Conclusion

The `FilesCache.php` file implements the abstract `Cache` class to provide file-based caching functionality. It includes methods to **connect** to the file system, **store** and **retrieve** cached data, **delete** cached data, check for the **existence** of cached data, and **clear** all cached data. This implementation allows developers to use the file system as a caching mechanism in their **PHPFast** applications.
{% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.cmsfullform.com/documents/drivers/cache/files-cache.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
