Readme

Cache Implementation Plan

Overview

This folder contains comprehensive documentation for implementing an advanced caching system with cross-server cache invalidation between the content management server and API server.


Documents

0-OCTOBER-CMS-ARTIFACTS-REPORT.md

Summary: Analysis of October CMS plugin artifacts remaining in the codebase.

Key Findings:


1-API-SERVER-IMPLEMENTATION.md

Summary: Implementation guide for the API server (api.testing.getubetter.com).

Key Features:

Implementation Phases:

  1. Enhanced GapCache (Week 1)
  2. Cache Management API (Week 1)
  3. Performance Monitoring (Week 2)
  4. Response Caching (Week 2-3)
  5. Testing & Documentation (Week 3)

Performance Targets:


2-CONTENT-SERVER-IMPLEMENTATION.md

Summary: Implementation guide for the content management server (testing.getubetter.com).

Key Features:

Models to Observe:

Implementation Phases:

  1. Configuration (Day 1)
  2. Service Layer (Day 2)
  3. Job & Queue (Day 3)
  4. Observers (Day 4-5)
  5. Testing (Day 6-7)
  6. Monitoring (Ongoing)

Critical Notes:


Quick Start

API Server Setup

# 1. Verify testing_logs database exists
mysql -u main -p'DevIMC2013!@' -e "SHOW DATABASES LIKE 'testing_logs';"

# 2. Check migrations ran
mysql -u main -p'DevIMC2013!@' testing_logs -e "SHOW TABLES;"

# 3. Verify Pulse configuration
grep "PULSE_" /var/www/api.testing/.env

# 4. Access Pulse dashboard
curl -H "Authorization: Bearer {JWT_TOKEN}" https://api.testing.getubetter.com/pulse

Content Server Setup (NOT DONE YET)

# 1. Add configuration to .env
vim /var/www/testing/.env
# Add CACHE_INVALIDATION_* variables

# 2. Create CacheInvalidationService class
# See 2-CONTENT-SERVER-IMPLEMENTATION.md Section 3

# 3. Create InvalidateApiCache job
# See 2-CONTENT-SERVER-IMPLEMENTATION.md Section 4

# 4. Add trait to models
# See 2-CONTENT-SERVER-IMPLEMENTATION.md Section 5

# 5. Test with a single model first
# Update a Webform and check logs

Architecture Diagram

┌─────────────────────────────────────────────────────────────┐
│                Content Management Server                      │
│              (testing.getubetter.com)                        │
│                    Laravel 9 + October CMS                   │
├─────────────────────────────────────────────────────────────┤
│                                                               │
│  1. User Updates Content (Webform, Pathway, etc.)           │
│          ↓                                                    │
│  2. Model Observer Fires (InvalidatesCacheOnChange trait)   │
│          ↓                                                    │
│  3. Async Job Dispatched (InvalidateApiCache)               │
│          ↓                                                    │
│  4. HTTP POST to API Server                                  │
│     POST /api/admin/cache/clear-model                        │
│     {"model": "webform", "id": 123}                          │
│                                                               │
└─────────────────────┬───────────────────────────────────────┘
                      │
                      │ HTTP/HTTPS
                      │
┌─────────────────────▼───────────────────────────────────────┐
│                     API Server                               │
│              (api.testing.getubetter.com)                   │
│                    Laravel 12 + Octane                       │
├─────────────────────────────────────────────────────────────┤
│                                                               │
│  5. CacheManagementController receives request              │
│          ↓                                                    │
│  6. GapCache::deletePattern("webform:123")                   │
│          ↓                                                    │
│  7. Redis SCAN for matching keys                             │
│          ↓                                                    │
│  8. Delete matched cache keys                                │
│          ↓                                                    │
│  9. Return success response                                  │
│     {"success": true, "keys_deleted": 8}                     │
│                                                               │
│  Meanwhile:                                                   │
│  - Pulse tracks slow queries (>200ms)                        │
│  - Pulse tracks slow endpoints (>500ms)                      │
│  - Middleware logs detailed slow request data                │
│  - All logged to testing_logs database                       │
│                                                               │
└─────────────────────────────────────────────────────────────┘

Cache Key Patterns

Webforms

Pathways

Accesscodes

Conditions


Database Structure

Main Database: testing_api (MySQL)

Logs Database: testing_logs (MySQL)

Cache: Redis


Performance Monitoring

Pulse Dashboard Metrics

Custom Slow Request Logging

Middleware logs additional context for requests >500ms:


Security

API Authentication

Logging


Monitoring & Alerts

What to Monitor

  1. Queue Length: Should be <100 most of the time
  2. Failed Jobs: Should be rare, investigate immediately
  3. Cache Hit Ratio: Target >80%
  4. API Response Times: Target <500ms for 95th percentile
  5. Redis Memory: Monitor for excessive growth

Where to Look


Troubleshooting

Cache Not Clearing

  1. Check content server logs: tail -f /var/www/testing/storage/logs/system.log
  2. Check queue worker: systemctl status laravel-queue-cache-invalidation
  3. Check API server logs: tail -f /var/www/api.testing/storage/logs/laravel.log
  4. Test manually: curl -X POST https://api.testing.getubetter.com/api/admin/cache/clear-pattern -H "Authorization: Bearer {TOKEN}" -d '{"pattern":"webform:*"}'

Slow Queries Not Showing

  1. Verify Pulse enabled: grep "PULSE_SLOW_QUERIES" /var/www/api.testing/.env
  2. Check threshold: Should be 200 (ms)
  3. Access Pulse dashboard: https://api.testing.getubetter.com/pulse
  4. Check testing_logs database: mysql -u main -p testing_logs -e "SELECT COUNT(*) FROM pulse_entries;"

Queue Not Processing

  1. Check worker status: systemctl status laravel-queue-cache-invalidation
  2. Check for stuck jobs: php artisan queue:failed
  3. Restart worker: systemctl restart laravel-queue-cache-invalidation
  4. Monitor in real-time: php artisan queue:work redis --queue=cache-invalidation -vvv

Testing Checklist

API Server Tests

Content Server Tests (when implemented)


Next Steps

Immediate (Completed ✅)

Short Term (This Week)

Medium Term (Next 1-2 Weeks)

Long Term (Next Month)


Resources

Documentation

Internal Docs


Contact

For questions or issues with this implementation:

  1. Review this documentation
  2. Check logs (see Monitoring & Alerts section)
  3. Test endpoints manually (see Troubleshooting section)
  4. Review Pulse/Telescope dashboards

Last Updated: January 14, 2026 Status: Documentation Complete, Implementation Pending