Skip to main content
Aeros provides cache management commands for clearing cache keys and flushing entire cache connections. The framework supports multiple cache drivers including Redis, Memcached, and local file-based caching.

cache:clear

Clears specific cache keys or flushes entire cache connections.
php aeros cache:clear
Arguments:
  • keys (optional, array) - Cache keys to delete in the format connection:key
Options:
  • -f, --flush - Flush all cache connections (destructive operation)

Clearing Specific Keys

Delete individual cache keys by specifying the connection and key name:
php aeros cache:clear redis-conn:cache.routes memcached-conn:cache.users
Key Format:
connection-name:cache-key
Examples:
php aeros cache:clear redis:cache.routes
# Deletes the 'cache.routes' key from the 'redis' connection
Use the wildcard * as the key name to flush all keys in a specific connection.

Flushing All Cache

Flush all cache connections defined in your configuration:
php aeros cache:clear --flush
Interactive Confirmation:
php aeros cache:clear --flush
# Prompts: "This action is destructive. Do you want to continue? [Y/n]"
The --flush option clears all data from all configured cache connections. This action cannot be undone.

Supported Cache Drivers

The cache:clear command supports different operations based on the cache driver:
Operations:
  • Check if key exists: EXISTS key
  • Delete key: DEL key
  • Flush connection: FLUSHDB
Example:
php aeros cache:clear redis:user.123
Operations:
  • Get key to check existence
  • Delete key: delete(key)
  • Flush connection: flush()
Example:
php aeros cache:clear memcached:session.abc123
Operations:
  • Deletes cache files from app/logs/cache/*.log
Example:
php aeros cache:clear local:*

Progress Indicator

When clearing multiple keys, a progress bar shows the operation status:
php aeros cache:clear redis:key1 redis:key2 memcached:key3

# Output:
# Are you sure you want to delete permanentely these keys? [y/N] y
# 3/3 [████████████████████] Deleting key: key3 100% 1 sec/1 sec
# Completed

Cache Configuration

Cache connections are defined in your config/cache.php file:
'connections' => [
    'redis' => [
        'driver' => 'redis',
        'host' => '127.0.0.1',
        'port' => 6379,
    ],
    'memcached' => [
        'driver' => 'memcached',
        'servers' => [
            ['host' => '127.0.0.1', 'port' => 11211]
        ],
    ],
    'local' => [
        'driver' => 'local',
    ],
],

Usage Examples

Clear Route Cache

php aeros cache:clear redis:cache.routes

Clear Multiple Middleware Caches

php aeros cache:clear memcached:cache.middleware.auth memcached:cache.middleware.cors

Flush Specific Connection

php aeros cache:clear redis:*

Clear Development Cache

# Clear all cache in development
php aeros cache:clear --flush

Selective Cache Clear

# Clear only user-related caches
php aeros cache:clear redis:users.* redis:sessions.*

Common Cache Keys

Depending on your Aeros application configuration, common cache keys might include:
  • cache.routes - Cached application routes
  • cache.config - Configuration cache
  • cache.middlewares - Middleware cache
  • cache.providers - Service provider cache
  • session.* - Session data
  • user.* - User-specific cache
During development, regularly clear your cache when making configuration changes:
php aeros cache:clear --flush

Error Handling

The command provides detailed error messages:
# Logged to application logs:
Key "cache.routes" was not found in "redis" cache connection
The command continues execution for remaining keys.
ERROR[Cache connection] Cache connection "invalid" not found.
Verify the connection name exists in config/cache.php.
ERROR[Cache driver] Cache driver "custom" is not supported.
Use Redis, Memcached, or local cache drivers.

Best Practices

Development

Use --flush frequently during development to ensure fresh cache

Production

Clear specific keys instead of flushing to avoid performance impact

Deployments

Clear cache after deploying configuration or route changes

Testing

Flush cache before running test suites for consistent results

Cache in Application Lifecycle

The run:app command automatically checks cache connectivity:
php aeros run:app
# ==> Checking default redis cache connection status... OK.
If cache is unavailable, the application won’t start. Use cache:clear to troubleshoot connection issues.

Next Steps

CLI Overview

Learn about other CLI commands

Cache Usage

Learn how to use cache in your application

Build docs developers (and LLMs) love