Complete ZiziCache REST API Reference

Updated on 12. 6. 2025

REST API Overview

ZiziCache provides a comprehensive REST API that enables programmatic control of cache management, optimization settings, and system monitoring. The API is designed for integration with automation tools, monitoring systems, and custom applications.

API Authentication

WordPress Nonce Authentication

All API requests require proper WordPress authentication:

Headers:
X-WP-Nonce: [nonce_value]
Content-Type: application/json

Getting Nonce Value

// JavaScript
const nonce = window.wpApiSettings.nonce;
// PHP
$nonce = wp_create_nonce('wp_rest');

Cache Management API

Cache Control Endpoints

Purge Pages Cache

POST /wp-json/zizi-cache/v1/cache/purge-pages

Clears all cached pages while preserving optimized assets.

Purge Everything

POST /wp-json/zizi-cache/v1/cache/purge-everything

Complete cache flush including pages and optimized files.

Preload Cache

POST /wp-json/zizi-cache/v1/cache/preload

Initiates background cache preloading process.

Cache Status

GET /wp-json/zizi-cache/v1/cache/status

Returns current cache status and statistics.

Response Example

{
  "success": true,
  "data": {
    "cache_enabled": true,
    "cached_pages": 150,
    "cache_size": "45.2 MB",
    "last_preload": "2024-12-11 10:30:00",
    "preload_status": "completed"
  }
}

Database Management API

Database Operations

Database Cleanup

POST /wp-json/zizi-cache/v1/database/cleanup
Content-Type: application/json
{
  "cleanup_types": [
    "db_post_revisions",
    "db_comments_spam",
    "db_transients_expired"
  ]
}

Database Statistics

GET /wp-json/zizi-cache/v1/database/statistics

Response Example

{
  "success": true,
  "data": {
    "total_size": "250.5 MB",
    "tables_count": 45,
    "post_revisions": 324,
    "spam_comments": 12,
    "expired_transients": 89,
    "optimization_recommendations": [
      "Remove 324 post revisions",
      "Clean 89 expired transients"
    ]
  }
}

Table Optimization

POST /wp-json/zizi-cache/v1/database/optimize-tables

Optimizes all database tables for better performance.

Index Recommendations API

Get Index Recommendations

GET /wp-json/zizi-cache/v1/database/index-recommendations

Apply Index Recommendations

POST /wp-json/zizi-cache/v1/database/apply-indexes
Content-Type: application/json
{
  "indexes": [
    "posts_status_date",
    "comments_approved_post"
  ]
}

OPcache Management API

OPcache Operations

OPcache Status

GET /wp-json/zizi-cache/v1/opcache/status

Response Example

{
  "success": true,
  "data": {
    "opcache_enabled": true,
    "cache_full": false,
    "hit_rate": 99.2,
    "memory_usage": {
      "used_memory": "45.6 MB",
      "free_memory": "82.4 MB",
      "wasted_memory": "1.2 MB"
    },
    "statistics": {
      "num_cached_scripts": 1250,
      "hits": 45600,
      "misses": 123,
      "blacklist_misses": 0
    }
  }
}

Flush OPcache

POST /wp-json/zizi-cache/v1/opcache/flush

OPcache Configuration

GET /wp-json/zizi-cache/v1/opcache/config

Returns current OPcache configuration settings.

Configuration Management API

Get Configuration

GET /wp-json/zizi-cache/v1/config

Returns complete ZiziCache configuration.

Update Configuration

POST /wp-json/zizi-cache/v1/config
Content-Type: application/json
{
  "enableCache": true,
  "cacheLifetimeHours": 24,
  "enablePreload": true,
  "css_minify": true,
  "js_minify": true,
  "fonts_optimize_google_fonts": true
}

Configuration Sections

Cache Settings

POST /wp-json/zizi-cache/v1/config/cache
Content-Type: application/json
{
  "enableCache": true,
  "cacheLifetimeHours": 48,
  "enablePreload": true
}

Optimization Settings

POST /wp-json/zizi-cache/v1/config/optimization
Content-Type: application/json
{
  "css_minify": true,
  "css_rucss": false,
  "js_minify": true,
  "js_defer": true,
  "img_lazyload": true
}

Font Intelligence API

Font Analysis

Analyze Fonts

POST /wp-json/zizi-cache/v1/font-intelligence/analyze
Content-Type: application/json
{
  "urls": [
    "/",
    "/about/",
    "/contact/"
  ]
}

Get Recommendations

GET /wp-json/zizi-cache/v1/font-intelligence/recommendations

Response Example

{
  "success": true,
  "data": {
    "recommendations": [
      {
        "font_family": "Open Sans",
        "confidence": 0.95,
        "action": "preload",
        "url": "https://fonts.gstatic.com/s/opensans/v18/mem8YaGs126MiZpBA-UFVZ0e.woff2"
      }
    ],
    "statistics": {
      "analyzed_urls": 3,
      "avg_confidence": 92,
      "total_recommendations": 1
    }
  }
}

Apply Recommendations

POST /wp-json/zizi-cache/v1/font-intelligence/apply-recommendations

Clear Font Intelligence Cache

POST /wp-json/zizi-cache/v1/font-intelligence/clear-cache

CDN Management API

CDN Configuration

Update CDN Settings

POST /wp-json/zizi-cache/v1/cdn/config
Content-Type: application/json
{
  "cdn_enabled": true,
  "cdn_url": "https://cdn.example.com",
  "cdn_excludes": [
    ".php",
    "/wp-admin/"
  ]
}

CDN Status

GET /wp-json/zizi-cache/v1/cdn/status

Performance Metrics API

System Performance

Get Performance Metrics

GET /wp-json/zizi-cache/v1/performance-metrics

Response Example

{
  "success": true,
  "current_metrics": {
    "memory_usage": {
      "current": 67108864,
      "peak": 94371840,
      "limit": "128M"
    },
    "database_performance": {
      "current_queries": 25,
      "query_time": 0.045,
      "slow_queries": 0
    },
    "http_performance": {
      "total_requests": 156,
      "average_response_time": 0.23,
      "error_rate": 0.02
    }
  },
  "analysis": {
    "database": {
      "status": "good",
      "message": "Database performance is optimal",
      "icon": "?"
    },
    "cache": {
      "status": "excellent",
      "message": "Cache system operating efficiently",
      "icon": "??"
    }
  }
}

Redis/Object Cache API

Redis Management

Redis Status

GET /wp-json/zizi-cache/v1/redis/status

Flush Redis Cache

POST /wp-json/zizi-cache/v1/redis/flush

Redis Statistics

GET /wp-json/zizi-cache/v1/redis/statistics

Action Scheduler API

Action Scheduler Management

Get Action Scheduler Status

GET /wp-json/zizi-cache/v1/action-scheduler/status

Clean Action Scheduler

POST /wp-json/zizi-cache/v1/action-scheduler/cleanup
Content-Type: application/json
{
  "logs_days": 30,
  "actions_days": 7
}

Error Handling

Standard Error Responses

{
  "success": false,
  "message": "Permission denied",
  "code": "rest_forbidden",
  "data": {
    "status": 403
  }
}

Common Error Codes

  • rest_forbidden (403): Insufficient permissions
  • rest_invalid_param (400): Invalid request parameters
  • rest_not_found (404): Endpoint not found
  • internal_error (500): Server error during operation

Rate Limiting

API endpoints implement rate limiting to prevent abuse:

  • Cache operations: 10 requests per minute
  • Configuration changes: 5 requests per minute
  • Status queries: 60 requests per minute
  • Heavy operations: 2 requests per minute

Integration Examples

JavaScript Integration

// Cache management
async function purgeCache() {
  const response = await fetch('/wp-json/zizi-cache/v1/cache/purge-pages', {
    method: 'POST',
    headers: {
      'X-WP-Nonce': wpApiSettings.nonce,
      'Content-Type': 'application/json'
    }
  });
  const result = await response.json();
  console.log('Cache purged:', result.success);
}
// Configuration update
async function updateSettings(config) {
  const response = await fetch('/wp-json/zizi-cache/v1/config', {
    method: 'POST',
    headers: {
      'X-WP-Nonce': wpApiSettings.nonce,
      'Content-Type': 'application/json'
    },
    body: JSON.stringify(config)
  });
  return await response.json();
}

PHP Integration

// Using WordPress HTTP API
function purge_cache_via_api() {
  $response = wp_remote_post(
    rest_url('zizi-cache/v1/cache/purge-pages'),
    array(
      'headers' => array(
        'X-WP-Nonce' => wp_create_nonce('wp_rest'),
        'Content-Type' => 'application/json'
      )
    )
  );
  if (!is_wp_error($response)) {
    $body = wp_remote_retrieve_body($response);
    $data = json_decode($body, true);
    return $data['success'];
  }
  return false;
}

cURL Examples

# Get cache status
curl -H "X-WP-Nonce: YOUR_NONCE" \
     -H "Content-Type: application/json" \
     https://your-site.com/wp-json/zizi-cache/v1/cache/status
# Purge cache
curl -X POST \
     -H "X-WP-Nonce: YOUR_NONCE" \
     -H "Content-Type: application/json" \
     https://your-site.com/wp-json/zizi-cache/v1/cache/purge-pages
# Update configuration
curl -X POST \
     -H "X-WP-Nonce: YOUR_NONCE" \
     -H "Content-Type: application/json" \
     -d '{"enableCache": true, "cacheLifetimeHours": 24}' \
     https://your-site.com/wp-json/zizi-cache/v1/config

Monitoring and Automation

Health Check Endpoint

GET /wp-json/zizi-cache/v1/health

Comprehensive system health check for monitoring tools.

Automated Workflows

  • CI/CD Integration: Automatic cache clearing on deployment
  • Monitoring Systems: Performance metrics collection
  • Load Balancers: Cache status for traffic routing
  • Backup Scripts: Configuration backup and restore

Security Considerations

API Security Best Practices

  • Nonce validation: Always validate WordPress nonces
  • Permission checks: Verify user capabilities
  • Input validation: Sanitize all input parameters
  • Rate limiting: Implement proper rate limiting
  • Logging: Log API access for security monitoring

Endpoint Security

  • All endpoints require authentication
  • Administrative operations require appropriate capabilities
  • Sensitive operations are rate-limited
  • Input validation prevents malicious requests

The ZiziCache REST API provides comprehensive programmatic access to all plugin functionality, enabling seamless integration with modern development workflows, monitoring systems, and automation tools. The API is designed with security, performance, and ease of use in mind.

What are your feelings