Jake Vanderwerf
2026-08-26 18e7e415339ccc9adf8ade562f93abef606da16d
=Cache::connects throughout codebase refactored
12 files modified
66 ■■■■■ changed files
inc/managers/NewsRelationships.php 1 ●●●●● patch | view | raw | blame | history
inc/managers/OperationQueue.php 2 ●●●●● patch | view | raw | blame | history
inc/managers/UserTermsManager.php 3 ●●●●● patch | view | raw | blame | history
inc/registrar/Registrar.php 2 ●●●●● patch | view | raw | blame | history
inc/registrar/config/seo/Resolver.php 2 ●●●●● patch | view | raw | blame | history
inc/registrar/config/seo/Schema.php 7 ●●●●● patch | view | raw | blame | history
inc/rest/Rest.php 8 ●●●●● patch | view | raw | blame | history
inc/rest/RestRouteManager.php 8 ●●●●● patch | view | raw | blame | history
inc/rest/routes/ContentTermsRoutes.php 12 ●●●●● patch | view | raw | blame | history
inc/rest/routes/Invitations.php 12 ●●●●● patch | view | raw | blame | history
inc/rest/routes/NotificationsRoutes.php 5 ●●●●● patch | view | raw | blame | history
src/summary/render.php 4 ●●●●● patch | view | raw | blame | history
inc/managers/NewsRelationships.php
@@ -16,6 +16,7 @@
class NewsRelationships
{
    private CustomTable $relationships;
    protected Cache $cache;
    public function __construct()
    {
inc/managers/OperationQueue.php
@@ -59,7 +59,7 @@
    {
        global $wpdb;
        $this->wpdb = $wpdb;
        $this->cache = Cache::for('queue', DAY_IN_SECONDS)->connect('user')->user();
        $this->cache = Cache::for('queue', 'user',DAY_IN_SECONDS)->user();
        add_action('jvb_process_queue', [ $this, 'checkQueue' ]);
        add_action('jvb_queue_maintenance', [$this, 'hourlyMaintenance']);
        add_action('jvbEmailDailyMetricsReport', [$this, 'emailDailyMetricsReport']);
inc/managers/UserTermsManager.php
@@ -67,8 +67,7 @@
     */
    public function clearUserCache(int $user_id, string|null $taxonomy = null):void
    {
        $cache = Cache::for($user_id.'_term_relationships', DAY_IN_SECONDS)->connect('post', true)->connect('taxonomy', true);
        $cache->flush();
        Cache::for($user_id.'_term_relationships')->flush();
    }
    /**
inc/registrar/Registrar.php
@@ -261,7 +261,7 @@
        foreach ($features as $feature) {
            foreach (self::withFeature($feature) as $instance) {
                $instance = self::getInstance($instance);
                $cache = Cache::for('tsf')->connect($instance->getType());
                $cache = Cache::for('tsf', $instance->getType());
                $cache->flush();
                $exclude = $cache->remember(
inc/registrar/config/seo/Resolver.php
@@ -223,7 +223,7 @@
                Cache::for('imageSchemaObject')->flush();
            }
            return Cache::for('imageSchemaObject')->connect('post')->remember(
            return Cache::for('imageSchemaObject', 'post')->remember(
                $imgID,
                function () use ($imgID, $img) {
                    $imageObject = new ImageObject();
inc/registrar/config/seo/Schema.php
@@ -54,9 +54,10 @@
        $this->referenceCache = Cache::for('schemaReference');
        $this->archiveCache = Cache::for('schemaArchive');
        if ($registrar) {
            $this->cache->connect($registrar->getType());
            $this->referenceCache->connect($registrar->getType());
            $this->archiveCache->connect($registrar->getType());
            $type = $registrar->getType();
            $this->cache = Cache::for('schema', $type);
            $this->referenceCache = Cache::for('schemaReference', $type);
            $this->archiveCache = Cache::for('schemaArchive', $type);
            switch ($registrar->getType()) {
                case 'term':
inc/rest/Rest.php
@@ -487,7 +487,7 @@
     */
    protected function checkUser(int $userId): bool
    {
        $cache = Cache::for('checkUser', DAY_IN_SECONDS)->connect('user');
        $cache = Cache::for('checkUser', 'user',DAY_IN_SECONDS);
        return $cache->remember($userId, fn() => (bool) get_userdata($userId));
    }
@@ -503,7 +503,7 @@
            return false;
        }
        $cache = Cache::for('checkTerm', DAY_IN_SECONDS)->connect('taxonomy');
        $cache = Cache::for('checkTerm', 'term', DAY_IN_SECONDS);
        return $cache->remember($termId, fn() => (bool) term_exists($termId, jvbCheckBase($taxonomy)));
    }
@@ -512,7 +512,7 @@
     */
    protected function isVerifiedUser(int $userId): bool
    {
        $cache = Cache::for('verifiedUsers', DAY_IN_SECONDS)->connect('user');
        $cache = Cache::for('verifiedUsers', 'user',DAY_IN_SECONDS);
        return $cache->remember($userId, fn() => user_can($userId, 'skip_moderation'));
    }
@@ -882,7 +882,7 @@
            return $terms;
        }
        $ids = array_map('absint', explode(',',$value));
        $cache = Cache::for('term_data')->connect('taxonomy');
        $cache = Cache::for('term_data','term');
        $cache->flush();
        if (!array_key_exists($taxonomy, $terms)) {
            $terms[$taxonomy] = [];
inc/rest/RestRouteManager.php
@@ -227,7 +227,7 @@
     */
    protected function checkUser(int $userID): bool
    {
        $cache = Cache::for('checkUser', DAY_IN_SECONDS)->connect('user');
        $cache = Cache::for('checkUser', 'user',DAY_IN_SECONDS);
        return $cache->remember($userID, function() use ($userID) {
            return (bool)get_userdata($userID);
@@ -239,7 +239,7 @@
     */
    protected function checkShop(int $shopID): bool
    {
        $cache = Cache::for('checkShop',DAY_IN_SECONDS)->connect('taxonomy');
        $cache = Cache::for('checkShop', 'term',DAY_IN_SECONDS);
        return $cache->remember($shopID, function() use ($shopID) {
            return (bool)term_exists($shopID, BASE . 'shop');
@@ -262,7 +262,7 @@
        }
        $taxonomy = jvbCheckBase($taxonomy);
        $cache = Cache::for('checkTerm', DAY_IN_SECONDS)->connect('taxonomy');
        $cache = Cache::for('checkTerm', 'term', DAY_IN_SECONDS);
        return $cache->remember($termID, function() use ($termID, $taxonomy) {
            return (bool)term_exists($termID, $taxonomy);
@@ -274,7 +274,7 @@
     */
    public function isVerifiedUser(int $user_id): bool
    {
        $cache = Cache::for('verifiedUsers', DAY_IN_SECONDS)->connect('user');
        $cache = Cache::for('verifiedUsers', 'user',DAY_IN_SECONDS);
        return $cache->remember($user_id, function() use ($user_id) {
            return user_can($user_id, 'skip_moderation');
inc/rest/routes/ContentTermsRoutes.php
@@ -51,7 +51,6 @@
            parent::__construct();
            $this->cache = Cache::for($this->taxonomy, 'term', DAY_IN_SECONDS);
            $this->setupTables();
            $this->setupCacheConnections();
        }
        add_action('init', [$this, 'registerContentTermsExecutors'], 5);
@@ -103,13 +102,6 @@
        }
    }
    protected function setupCacheConnections(): void
    {
        $this->cache
            ->connect('taxonomy')
            ->connect('user');
    }
    public function registerRoutes(): void
    {
        if (!$this->registrar->hasFeature('is_content')) {
@@ -262,7 +254,7 @@
        $page = (int)$request->get_param('page');
        return $this->cache->remember(compact('termID', 'status', 'page'), function() use ($termID, $status, $page) {
        return $this->cache->remember(['id'=> $termID, 'status' => $status, 'page' => $page], function() use ($termID, $status, $page) {
            $perPage = 20;
            $offset = ($page - 1) * $perPage;
@@ -333,7 +325,7 @@
        $status = $request->get_param('status');
        $page = (int)$request->get_param('page');
        return $this->cache->remember(compact('termID', 'status', 'page'), function() use ($termID, $status, $page) {
        return $this->cache->remember(['id'=>$termID, 'status' => $status,'page' => $page], function() use ($termID, $status, $page) {
            $perPage = 20;
            $offset = ($page - 1) * $perPage;
inc/rest/routes/Invitations.php
@@ -2,7 +2,9 @@
namespace JVBase\rest\routes;
use JVBase\Instance;
use JVBase\managers\Cache;
use JVBase\managers\InvitationsManager;
use JVBase\managers\Roles;
use JVBase\rest\Rest;
use JVBase\managers\CustomTable;
use JVBase\rest\Route;
@@ -25,20 +27,18 @@
    use Instance;
    protected array $inviteConfig;
    protected CustomTable $table;
    protected Cache $termCache;
    public function __construct()
    {
        $this->cacheName = 'invitations';
        parent::__construct();
        $this->cache = Cache::for('invitations_posts','post');
        $this->termCache = Cache::for('invitation_terms', 'term');
        // Get invitation configuration
        $this->inviteConfig = InvitationsManager::getInstance()->getInviteConfig();
        $this->table = CustomTable::for('invitations');
        // Cache connections
        $this->cache
            ->connect('user')
            ->connect('taxonomy');
    }
    public function registerRoutes(): void
@@ -80,7 +80,7 @@
        }
        $args = [
            'user' => $userID,
            'id' => $userID,
            'to_term' => $termID,
            'taxonomy' => $taxonomy ? jvbNoBase($taxonomy) : null,
            'status' => $request->get_param('status'),
inc/rest/routes/NotificationsRoutes.php
@@ -109,10 +109,7 @@
        $this->cacheName = 'notifications';
        $this->cacheTtl = HOUR_IN_SECONDS;
        parent::__construct();
        // Connect notifications cache to user cache
        // When user data changes, notification cache should invalidate
        $this->cache->connect('user');
        $this->cache = Cache::for($this->cacheName, 'user', $this->cacheTtl);
        $this->notifications = CustomTable::for('notifications');
        $this->metrics = CustomTable::for('notification_metrics');
src/summary/render.php
@@ -165,7 +165,7 @@
{
    $current = get_queried_object();
    $cache = Cache::for('shop_bio', WEEK_IN_SECONDS)->connect('taxonomy');
    $cache = Cache::for('shop_bio', 'term',WEEK_IN_SECONDS);
    $key = $current->term_id;
    $cached = $cache->get($key);
    if ($cached !== false) {
@@ -285,7 +285,7 @@
function jvbRenderTermSummary()
{
    $current = get_queried_object();
    $cache = Cache::for('term_summary', WEEK_IN_SECONDS)->connect('taxonomy');
    $cache = Cache::for('term_summary', 'term',WEEK_IN_SECONDS);
    $key = $current->ID;
    $cached = $cache->get($key);
    if ($cached !== false) {