# Guide Usage Cache

The `Cache.php` file in the `system/Drivers/Cache/` directory of the **PHPFast** framework is an abstract class that provides the basic methods for managing cache. This class defines abstract methods that must be implemented by its subclasses, creating a consistent interface for storing and retrieving cached data.

## **Cache Initialization**:

* The constructor method accepts cache configuration and calls the method to connect to the specific cache driver.

## **Connecting to Cache Driver**:

* The abstract method `connect()` is used to connect to specific cache drivers such as Redis, File-based, etc.

## **Storing and Retrieving Cached Data**:

The `Cache.php` class defines the following abstract methods, which are implemented in subclasses to handle **cache operations efficiently**:

* **`set($key, $value, $ttl)`** – Stores data in the cache with a specified time-to-live (TTL).
* **`get($key)`** – Retrieves cached data using a unique key.
* **`delete($key)`** – Removes a specific item from the cache.
* **`has($key)`** – Checks if a key exists in the cache.
* **`clear()`** – Clears all cached data.

These methods ensure a **consistent and structured approach** to cache management across different caching backends.

## Configuration Cache

See more at [Configurations](/overview/install/configurations.md)

## Example Usage of `Cache.php`

### **Storing Data in Cache**

```php
<?php
// Create a cache object
$cache = new RedisCache($config);

$phpFast = 'Welcome to PHPFast Framework";

// Store data in cache with a TTL of 10 minutes (600 seconds)
$cache->set('php_fast', $phpFast, 600);
```

### **Retrieving Data from Cache**

```php
<?php
// Retrieve data from cache
$phpFast = $cache->get('php_fast');

if ($phpFast !== null) {
    // Data found in cache
    echo "Data loaded from cache.";
} else {
    // Data not found in cache, need to load from another source
    echo "Data not found in cache.";
}
```

### **Deleting Data from Cache**

```php
<?php
// Delete data from cache
$cache->delete('php_fast');
```

## Subclasses of `Cache.php`

The `Cache.php` class acts as a **parent class** for multiple subclasses, each implementing its own caching mechanism while adhering to the standard interface defined in `Cache.php`. Key subclasses include:

* &#x20;[**`UriCache.php`**](/documents/drivers/cache/uri-cache.md) – Optimizes request handling by caching URI-based data.
* &#x20;[**`RedisCache.php`**](/documents/drivers/cache/redis-cache.md) – Provides high-performance caching using Redis.
* &#x20;[**`FilesCache.php`**](/documents/drivers/cache/files-cache.md) – Implements file-based caching by storing data in structured files.

Each subclass implements the abstract methods defined in `Cache.php`, ensuring a modular and extensible caching system within the PHPFast framework.


---

# Agent Instructions: 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:

```
GET https://docs.cmsfullform.com/documents/drivers/cache/guide-usage-cache.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
