From 18e7e415339ccc9adf8ade562f93abef606da16d Mon Sep 17 00:00:00 2001
From: Jake Vanderwerf <get@jakevanderwerf.ca>
Date: Wed, 26 Aug 2026 22:24:18 +0000
Subject: [PATCH] =Cache::connects throughout codebase refactored
---
inc/managers/UserTermsManager.php | 3 -
inc/managers/OperationQueue.php | 2
inc/rest/Rest.php | 8 ++--
inc/registrar/config/seo/Resolver.php | 2
inc/rest/RestRouteManager.php | 8 ++--
inc/managers/NewsRelationships.php | 1
src/summary/render.php | 4 +-
inc/rest/routes/Invitations.php | 12 +++---
inc/rest/routes/NotificationsRoutes.php | 5 --
inc/registrar/Registrar.php | 2
inc/registrar/config/seo/Schema.php | 7 ++-
inc/rest/routes/ContentTermsRoutes.php | 12 +-----
12 files changed, 28 insertions(+), 38 deletions(-)
diff --git a/inc/managers/NewsRelationships.php b/inc/managers/NewsRelationships.php
index 0f6b7a9..f42f22b 100644
--- a/inc/managers/NewsRelationships.php
+++ b/inc/managers/NewsRelationships.php
@@ -16,6 +16,7 @@
class NewsRelationships
{
private CustomTable $relationships;
+ protected Cache $cache;
public function __construct()
{
diff --git a/inc/managers/OperationQueue.php b/inc/managers/OperationQueue.php
index 77ba35a..be4139c 100644
--- a/inc/managers/OperationQueue.php
+++ b/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']);
diff --git a/inc/managers/UserTermsManager.php b/inc/managers/UserTermsManager.php
index 5ce2829..590d37e 100644
--- a/inc/managers/UserTermsManager.php
+++ b/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();
}
/**
diff --git a/inc/registrar/Registrar.php b/inc/registrar/Registrar.php
index 821c6db..7c872fd 100644
--- a/inc/registrar/Registrar.php
+++ b/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(
diff --git a/inc/registrar/config/seo/Resolver.php b/inc/registrar/config/seo/Resolver.php
index f7cde47..0f77663 100644
--- a/inc/registrar/config/seo/Resolver.php
+++ b/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();
diff --git a/inc/registrar/config/seo/Schema.php b/inc/registrar/config/seo/Schema.php
index e12796f..e898c38 100644
--- a/inc/registrar/config/seo/Schema.php
+++ b/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':
diff --git a/inc/rest/Rest.php b/inc/rest/Rest.php
index 621329e..4238e96 100644
--- a/inc/rest/Rest.php
+++ b/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] = [];
diff --git a/inc/rest/RestRouteManager.php b/inc/rest/RestRouteManager.php
index a474aaa..34cf72f 100644
--- a/inc/rest/RestRouteManager.php
+++ b/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');
diff --git a/inc/rest/routes/ContentTermsRoutes.php b/inc/rest/routes/ContentTermsRoutes.php
index 8f2270a..1884aeb 100644
--- a/inc/rest/routes/ContentTermsRoutes.php
+++ b/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;
diff --git a/inc/rest/routes/Invitations.php b/inc/rest/routes/Invitations.php
index 9dbb49f..ded90c6 100644
--- a/inc/rest/routes/Invitations.php
+++ b/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'),
diff --git a/inc/rest/routes/NotificationsRoutes.php b/inc/rest/routes/NotificationsRoutes.php
index 90af2be..fd04460 100644
--- a/inc/rest/routes/NotificationsRoutes.php
+++ b/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');
diff --git a/src/summary/render.php b/src/summary/render.php
index b5645eb..4602359 100644
--- a/src/summary/render.php
+++ b/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) {
--
Gitblit v1.10.0