get( 'bypass_shared_cache', false ); /** * Force the agent endpoints uncacheable (send `no-store`) so every fetch reaches * WordPress — the activity log counts it and freshness-sensitive docs stay current. * * @param bool $on Whether to keep the AI endpoints out of shared caches. */ return (bool) apply_filters( 'agentimus_bypass_shared_cache', $on ); } /** * The Cache-Control value for a cacheable endpoint, given the bypass choice. Pure — * `no-store` keeps it out of every cache; otherwise it stays edge-cacheable. Unit-tested. * * @param bool $bypass Whether to keep it out of shared caches. * @param int $max_age Seconds a cache may hold it when NOT bypassing. * @return string */ public static function value( $bypass, $max_age ) { return $bypass ? 'no-store, max-age=0' : 'public, max-age=' . max( 0, (int) $max_age ); } /** * Emit the Cache-Control for a cacheable agent endpoint — and, when the switch is on, * a `CDN-Cache-Control: no-store` the edge reads too (Cloudflare, Fastly, Akamai). * Call inside a `! headers_sent()` guard, as every caller already is. * * @param int $max_age Seconds a cache may hold this when NOT bypassing. Default one hour. */ public static function send( $max_age = 3600 ) { $bypass = self::bypass(); header( 'Cache-Control: ' . self::value( $bypass, $max_age ) ); if ( $bypass ) { // The same `no-store` the .md endpoints already send; CDN-Cache-Control says it // at the edge specifically, for a CDN that reads that in preference. header( 'CDN-Cache-Control: no-store' ); } } }