---
url: https://apexfluently.beyondthecloud.dev/libraries/cache-manager.md
description: >-
  Simple caching for Salesforce Apex. Transaction, Session, and Org Cache with
  fluent API. Improve performance with easy get, put, remove operations.
---

# Cache Manager

A simple way to cache data in Salesforce Apex.

## What Does It Solve?

* **Code Performance** - Repeatedly loading the same data impacts performance.

## Why Cache Manager?

* **Fluent API** - Call different methods to work with the cache: get, put, remove, contains, etc.
* **Custom Cache Instances** - Create your own platform cache instance and add it to the Cache Manager.
* **Error Handling** - Automatic key validation and fallback.

## Quick Start

```apex
CacheManager.ApexTransaction.put('YourKey', 'Value');
CacheManager.DefaultOrgCache.put('YourKey', 'Value');
CacheManager.DefaultSessionCache.put('YourKey', 'Value');

// eg.
CacheManager.ApexTransaction.put(
    UserInfo.getUserId(),
    [SELECT Id, Name, Country FROM User WHERE Id = :UserInfo.getUserId()]
);

User currentUser = (User) CacheManager.ApexTransaction.get(UserInfo.getUserId());
```

## Documentation

* [GitHub Repository](https://github.com/beyond-the-cloud-dev/cache-manager)

## Installation

* [Copy and Deploy](https://github.com/beyond-the-cloud-dev/cache-manager/tree/main/force-app/main/default)
