Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/Ahondev/portfolio-v2/llms.txt

Use this file to discover all available pages before exploring further.

Every database query in WP SSR Framework — whether in a web controller, an API controller, or a view composer — can be wrapped in a single caching primitive: Base::remember(). This method stores the result of any callback in a WordPress transient for a configurable TTL, short-circuiting repeated queries on subsequent requests. Alongside it, CacheServiceProvider adds a prominent ”🧹 Vider le cache” button to the WP admin bar, giving administrators a one-click escape hatch whenever stale data appears after a deployment or bulk content update.

Base::remember() — The Core Caching Primitive

remember() is defined on the Base class, which all controllers and composers extend. It wraps WordPress’s native transient API in a thin, readable interface.
protected function remember(string $key, int $ttl, callable $callback)
{
    $cached = get_transient($key);

    if ($cached !== false) {
        return $cached;
    }

    $data = $callback();
    set_transient($key, $data, $ttl);

    return $data;
}
Parameters:
ParameterTypeDescription
$keystringUnique transient key. Use a versioned suffix (e.g. _v1) to bust the cache on deploys.
$ttlintTime-to-live in seconds. Pass 0 for no expiry.
$callbackcallableThe expensive operation whose result should be cached.
On a cache hit, get_transient() returns the stored value and the callback is never invoked. On a cache miss (first call, or after expiry), the callback runs, its return value is stored, and that value is returned.
WordPress get_transient() returns false both when the key doesn’t exist and when it has expired. Do not store the literal boolean false as a cached value — it will always be treated as a miss.

Real-World Examples

Both AppComposer and HomeController cache the same service query with a 5-minute TTL (300 seconds). They intentionally share the key composer_services_v1 so the result is computed once and reused across both the global composer and the home page controller.
AppComposer::compose() runs for every view (views() returns ['*']). Caching here prevents the Service::query()->all() call from firing on every single page load.
// app/Composers/AppComposer.php
public function compose(): array
{
    $services = $this->remember('composer_services_v1', 300, function () {
        return Service::query()->all();
    });

    return [
        'site_email'    => get_field('email', 'option'),
        'site_services' => $services,
    ];
}
Append a version suffix to your cache keys (e.g. composer_services_v2) whenever you change the shape of the cached data. This ensures old cached values are abandoned rather than accidentally served to the new code.

Admin Bar Cache Flush

CacheServiceProvider::boot() adds a ”🧹 Vider le cache” node to the WordPress admin bar, visible only to users with the manage_options capability.
$wp_admin_bar->add_node([
    'id'    => 'flush-cache',
    'title' => '🧹 Vider le cache',
    'href'  => admin_url('admin-post.php?action=flush_cache&nonce=' . $nonce),
    'meta'  => [
        'class' => 'flush-cache-btn',
        'title' => 'Vider tout le cache',
    ],
]);
Clicking the button navigates to an admin-post handler that:
1

Verify permissions and nonce

The handler checks current_user_can('manage_options') and validates the flush_cache_action nonce. An invalid request is rejected with a 403 response.
2

Delete all transients from the database

Two raw $wpdb queries remove every transient and its timeout option row:
$wpdb->query("DELETE FROM {$wpdb->options} WHERE option_name LIKE '_transient_%'");
$wpdb->query("DELETE FROM {$wpdb->options} WHERE option_name LIKE '_transient_timeout_%'");
3

Flush the object cache

If an external object cache (Redis, Memcached) is active, wp_cache_flush() is called to purge it as well.
if (function_exists('wp_cache_flush')) {
    wp_cache_flush();
}
4

Redirect with success notice

The handler redirects back to the referring admin page and appends ?cache_flushed=1. The admin_notices hook picks this up and displays a green dismissible banner: ”🧹 Cache vidé avec succès”.

When to Flush the Cache

SituationAction
Deploying new code that changes query results or data shapesFlush immediately after deployment
Bulk updating or importing postsFlush after the import completes
Stale data appearing on the frontendFlush from the admin bar
Changing ACF field values that are cachedFlush, or lower the TTL for that query
After clearing the SSG static file cacheConsider flushing transients too for consistency
The rate limiter (see Rate Limiting) stores its counters in WordPress transients. Flushing the cache resets all rate-limit windows, which may temporarily allow burst traffic from previously limited IPs.

Rate Limiting

Rate-limit counters are stored as transients — understand the interaction before flushing in production.

Static Site Generation

SSG stores pre-rendered HTML on disk, separate from the transient cache — learn how the two layers complement each other.

Build docs developers (and LLMs) love