---
title: "Cache Overview | DreamFactory Docs"
source: "https://docs.dreamfactory.com/api-generation-and-connections/api-types/cache/cache-overview"
canonical_url: "https://docs.dreamfactory.com/api-generation-and-connections/api-types/cache/cache-overview"
converted_at: "2026-04-22T14:32:37.005Z"
format: "markdown"
converted_by: "html-to-md-ai"
---
DreamFactory supports multiple caching backends to improve API performance. Caching stores frequently accessed data in memory, reducing database load and improving response times for read-heavy workloads.

---

## Supported Cache Services[​](#supported-cache-services)

ServiceTypeUse CaseDocumentation**Redis**In-memory storeProduction caching, sessions, queues[Redis Guide](/api-generation-and-connections/api-types/cache/redis)**Memcached**In-memory cacheSimple key-value caching[Memcached Guide](/api-generation-and-connections/api-types/cache/memcached)**Local**File-basedDevelopment, single-instance deploymentsBuilt-in**File**File-basedDevelopment, disk-based persistenceBuilt-in**Database**SQL-backedSimple deployments without external cacheBuilt-in

---

## Cache Use Cases in DreamFactory[​](#cache-use-cases-in-dreamfactory)

### API Response Caching[​](#api-response-caching)

Cache API responses to reduce database queries:

- **Per-service caching**: Enable caching on individual database or file services

- **TTL configuration**: Set expiration times based on data volatility

- **Cache invalidation**: Automatic clearing on write operations

### Session Storage[​](#session-storage)

Store user sessions in a distributed cache:

- **Scalability**: Share sessions across multiple DreamFactory instances

- **Performance**: Faster session lookups than database

- **Persistence**: Redis can persist sessions across restarts

### Rate Limiting[​](#rate-limiting)

Track API request counts per user or role:

- **Distributed counting**: Works across load-balanced instances

- **Atomic operations**: Accurate request tracking

- **Automatic expiry**: Counters reset after time windows

---

## Choosing a Cache Backend[​](#choosing-a-cache-backend)

### Redis vs Memcached[​](#redis-vs-memcached)

FeatureRedisMemcachedData structuresStrings, lists, sets, hashes, sorted setsStrings onlyPersistenceOptional disk persistenceMemory onlyReplicationMaster-slave, clusteringNone (client-side)Pub/SubYesNoLua scriptingYesNoMemory efficiencyGoodExcellent for simple dataMax key size512 MB1 MBUse caseFeature-rich, sessions, queuesSimple caching

### Recommendation[​](#recommendation)

- **Production**: Use **Redis** for its flexibility, persistence options, and support for sessions

- **Development**: Use **Local** cache for simplicity

- **High-volume simple caching**: Use **Memcached** for maximum memory efficiency

---

## Cache Architecture[​](#cache-architecture)

```
┌─────────────────┐     ┌──────────────────┐     ┌─────────────────┐│   API Client    │────▶│   DreamFactory   │────▶│    Database     ││                 │◀────│                  │◀────│                 │└─────────────────┘     └────────┬─────────┘     └─────────────────┘                                 │                                 │ Cache check                                 ▼                        ┌─────────────────┐                        │  Cache Backend  │                        │  (Redis/Memcached)                        └─────────────────┘
```

### Cache Flow[​](#cache-flow)

1. **Request arrives** at DreamFactory

2. **Cache check**: If cached response exists and is valid, return it

3. **Cache miss**: Query the database/service

4. **Store in cache**: Save response with configured TTL

5. **Return response** to client

### Cache Invalidation[​](#cache-invalidation)

DreamFactory automatically invalidates cache entries when:

- **POST/PUT/PATCH/DELETE** operations modify data

- **TTL expires** based on configured duration

- **Manual flush** via admin API

---

## Configuring Cache Services[​](#configuring-cache-services)

### System-Wide Cache[​](#system-wide-cache)

Configure the default cache backend in DreamFactory's environment:

```
CACHE_DRIVER=redisREDIS_HOST=localhostREDIS_PORT=6379REDIS_PASSWORD=your_password
```

### Per-Service Caching[​](#per-service-caching)

Enable caching on individual services:

1. Navigate to the service configuration

2. Enable **Cache Enabled** option

3. Set **Cache TTL** in seconds

4. Save the service

---

## Cache API Endpoints[​](#cache-api-endpoints)

DreamFactory exposes a Cache API for direct cache operations:

MethodEndpointDescription`GET``/api/v2/{cache_service}/{key}`Get cached value`POST``/api/v2/{cache_service}`Store value in cache`DELETE``/api/v2/{cache_service}/{key}`Delete cached value`DELETE``/api/v2/{cache_service}`Flush all cached values

### Example: Store a Value[​](#example-store-a-value)

```
curl -X POST "https://example.com/api/v2/cache" \  -H "X-DreamFactory-API-Key: YOUR_API_KEY" \  -H "Content-Type: application/json" \  -d '{    "key": "user:123:profile",    "value": {"name": "John", "email": "[email protected]"},    "ttl": 3600  }'
```

### Example: Retrieve a Value[​](#example-retrieve-a-value)

```
curl -X GET "https://example.com/api/v2/cache/user:123:profile" \  -H "X-DreamFactory-API-Key: YOUR_API_KEY"
```

---

## Performance Best Practices[​](#performance-best-practices)

### TTL Configuration[​](#ttl-configuration)

Data TypeRecommended TTLRationaleStatic reference data24 hoursRarely changesUser profiles5-15 minutesBalances freshness and performanceReal-time data30-60 secondsFrequently updatedSession data30 minutes - 2 hoursMatches session duration

### Cache Key Design[​](#cache-key-design)

Use structured, predictable key patterns:

```
{resource_type}:{id}:{sub_resource}
```

Examples:

- `user:123:profile`

- `product:456:inventory`

- `order:789:items`

### Memory Management[​](#memory-management)

- **Monitor memory usage** to prevent eviction

- **Set appropriate TTLs** to expire stale data

- **Use Redis maxmemory-policy** for graceful eviction

---

## Common Errors[​](#common-errors)

Error CodeMessageCauseSolution400Bad RequestInvalid key or value formatCheck request payload401UnauthorizedMissing API keyAdd API key header404Not FoundKey does not existHandle cache miss in client503Service UnavailableCache backend unreachableCheck cache server status

---

## Next Steps[​](#next-steps)

- **[Redis](/api-generation-and-connections/api-types/cache/redis)**: Configure Redis for production caching

- **[Memcached](/api-generation-and-connections/api-types/cache/memcached)**: Configure Memcached for simple caching

- **[Performance Tuning](/administration/performance-tuning)**: Optimize DreamFactory performance