---
title: "Festi Cache"
url: https://festi.dev/8.0/Packages/Cache/
---

# Festi Cache

Festi Cache is a flexible caching library for the Festi Framework, providing multiple cache adapters including **Memcache, Memcached, ArrayCache, and Pear Cache Lite**. It allows efficient caching of data to improve application performance.

## Installation

To install Festi Cache via Composer, add the following to your `composer.json`:

```json
{
    "require": {
        "festi-team/festi-framework-cache": "dev-master"
    }
}
```

## Usage

### Initializing Cache

To use Festi Cache, initialize an adapter:

```php
$cache = new Cacher(new MemcachedAdapter());
```

### Storing and Retrieving Data

```php
$key = 'user_123';
$value = ['name' => 'John Doe', 'email' => 'john@example.com'];
$cache->set($key, $value, 3600); // Store for 1 hour

$data = $cache->get($key);
var_dump($data);
```

### Deleting Cached Data

```php
$cache->delete($key);
```

## Available Cache Adapters

Festi Cache supports multiple caching backends:

- **MemcacheAdapter** – Uses PHP’s `memcache` extension.
- **MemcachedAdapter** – Uses `memcached` extension for improved performance.
- **ArrayCacheAdapter** – In-memory caching for temporary storage.
- **PearCacheLiteAdapter** – Uses PEAR’s `Cache_Lite` for lightweight file-based caching.

## Exception Handling

Festi Cache provides built-in exception handling:

```php

try {
    $cache->set($key, $value, -1); // Invalid expiration time
} catch (CacheException $e) {
    echo "Cache error: " . $e->getMessage();
}
```
