Skip to content

Redis/Predis Cache Architecture

🔴 What's Cached in Redis (vs Database Storage)

1. MENUS ⚠️ This is your issue!

Cache Type: rememberForever() - Stored indefinitely until manually cleared

Location: app/Services/Common/MenuService.php:106

cache()->rememberForever(self::MENU_KEY, function () {
    // Menu items are cached forever
});

Cached Data: - All menu items and their children - Menu structure and hierarchy - Menu permissions per user role - Frontend and admin menus

Why Your Menu is Outdated: The menu uses rememberForever() which means it's cached indefinitely in Redis. When you sync the database, the Redis cache still has the old menu data.

How to Fix:

# SSH to your server and run:
php artisan cache:forget menu
# OR clear all cache:
php artisan cache:clear


2. DASHBOARD WIDGETS & ANALYTICS

Cache Type: remember() with 300 second (5 minute) TTL

Location: app/Services/Dashboard/DashboardService.php:59

Cached Data: - daily_users - User registration statistics - sales_previous_week - Previous week sales data - sales_this_week - Current week sales data - api_cost_distribution - API usage costs - popular_plans_data - Popular subscription plans - popular_tools_data - Most used AI tools - top_countries - Geographic user distribution - user_traffic - Traffic analytics - generated_content - Content generation stats - dashboard_widgets - Widget configuration

Refresh Rate: Auto-refreshes every 5 minutes


3. SETTINGS & CONFIGURATION

Cache Type: Mixed (some forever, some with TTL)

Cached Settings: - vip_membership - VIP membership status - Frontend section settings (via Observers) - Frontend settings (cached forever until changed) - OpenAI generator settings (cached forever) - Ad settings (cached forever) - Feature marquee settings (cached forever)

Location: Observers in app/Observer/

Refresh: Automatically cleared when settings are updated via admin panel


4. USER SESSION DATA

Cache Type: Session driver (Redis)

Stored Data: - User authentication state - CSRF tokens - Flash messages - Current cart data - User preferences during session

Refresh: Cleared on logout or session expiration (120 minutes by default)


5. BLADE TEMPLATE CACHE

Cache Type: File cache + Redis

Location: storage/framework/views/ (compiled templates)

Cached Data: - Compiled Blade templates - View partials - Component cache

Clear with:

php artisan view:clear


6. EXTENSIONS & MARKETPLACE

Cache Type: remember() with various TTLs

Cached Data: - Installed extensions list - Extension metadata - Extension permissions - Marketplace listings

Refresh: Cleared when extensions are installed/uninstalled


7. FONTS SERVICE

Cache Type: rememberForever()

Location: app/Services/Common/FontsService.php

Cached Data: - Available fonts list - Font metadata


📊 What's NOT Cached (Always from Database)

✅ Real-time Data:

  • User accounts and profiles
  • Subscriptions and orders
  • Usage credits and tokens
  • AI generation history
  • Support tickets
  • User files and documents
  • Payment transactions
  • Chatbot conversations
  • Email templates
  • Blog posts and pages
  • User activity logs

✅ Critical Security Data:

  • Passwords (hashed in DB)
  • API keys
  • OAuth tokens
  • Two-factor authentication codes
  • Password reset tokens

🔧 How to Clear Specific Caches

Clear Everything (Nuclear Option):

php artisan cache:clear
php artisan config:clear
php artisan view:clear
php artisan route:clear

Clear Specific Items:

# Menu cache (your issue!)
php artisan tinker
>>> cache()->forget('menu');
>>> exit

# Dashboard widgets
>>> cache()->forget('dashboard_widgets');

# Specific dashboard stats
>>> cache()->forget('sales_this_week');
>>> cache()->forget('sales_previous_week');
>>> cache()->forget('popular_plans_data');

Clear All Dashboard Stats:

php artisan tinker
>>> cache()->flush(); // Clears ALL Redis cache

🚀 Quick Fix for Your Outdated Menu

After syncing your database to a new environment, always clear the cache:

# On your server (via SSH):
cd /var/www/html
php artisan cache:clear
php artisan config:cache
php artisan view:clear

# Or just the menu:
php artisan tinker
>>> cache()->forget('menu');

🔄 Cache Refresh Workflow After DB Sync

When you use the Database Sync feature, here's what you should do:

  1. Sync Database (via Admin UI or script)
  2. SSH to target server
  3. Clear caches:
    php artisan cache:clear
    php artisan config:cache
    php artisan view:clear
    
  4. Restart queue workers (if using queues):
    php artisan queue:restart
    

💡 Pro Tip: Add to Your CI/CD

Add this to your deployment script after database syncs:

# In your CodeDeploy scripts/hooks:
php artisan cache:clear
php artisan config:cache
php artisan view:clear
php artisan queue:restart

🔍 How to Check What's in Redis

# Connect to Redis
redis-cli -h master.prod-redis.m0zcou.use1.cache.amazonaws.com \
          --tls -p 6379 \
          -a "YourPasswordHere"

# List all keys
KEYS *

# Get a specific key
GET laravel_cache:menu

# Delete a specific key
DEL laravel_cache:menu

# Clear everything (DANGEROUS!)
FLUSHALL

Summary Table

Data Type Cache Duration Storage Clear Method
Menus Forever ⚠️ Redis cache()->forget('menu')
Dashboard Stats 5 minutes Redis Auto-refresh or cache:clear
Settings Forever Redis Auto-clears on update
Sessions 120 minutes Redis Auto-expires
Blade Templates Forever Files view:clear
User Data Never Database N/A
Orders Never Database N/A
Subscriptions Never Database N/A
Credits/Tokens Never Database N/A

Your Issue: The menu is cached forever in Redis, so after syncing the database, the old menu structure remains until you manually clear the cache!