From 0afb2c0046b55c123eafb4ab9ee77efa68d12463 Mon Sep 17 00:00:00 2001
From: Jake Vanderwerf <get@jakevanderwerf.ca>
Date: Sat, 06 Jun 2026 17:15:31 +0000
Subject: [PATCH] =Starting the Favourites.js setup, converting previous Northeh stuff to new Registrar, fixing up Square.php integration to match
---
inc/managers/Cache.php | 66 +++++++++++++++++++++++----------
1 files changed, 46 insertions(+), 20 deletions(-)
diff --git a/inc/managers/Cache.php b/inc/managers/Cache.php
index e7ebc94..c144013 100644
--- a/inc/managers/Cache.php
+++ b/inc/managers/Cache.php
@@ -18,6 +18,8 @@
private static array $instances = [];
private bool $hasRedis;
+ private bool $varyByAuth = false;
+ private bool $varyByUser = false;
private function __construct(string $group, int $ttl)
{
@@ -32,10 +34,10 @@
add_action('save_post', [self::class, 'onPostChange'], 10, 2);
add_action('delete_post', [self::class, 'onPostDelete']);
- // Post meta updates
- add_action('updated_post_meta', [self::class, 'onPostMetaChange'], 10, 2);
- add_action('added_post_meta', [self::class, 'onPostMetaChange'], 10, 2);
- add_action('deleted_post_meta', [self::class, 'onPostMetaDelete'], 10, 2);
+ // Post meta updates, now handled via Meta.php?
+// add_action('updated_post_meta', [self::class, 'onPostMetaChange'], 10, 2);
+// add_action('added_post_meta', [self::class, 'onPostMetaChange'], 10, 2);
+// add_action('deleted_post_meta', [self::class, 'onPostMetaDelete'], 10, 2);
// Term updates (all taxonomies)
add_action('edited_term', [self::class, 'onTermChange'], 10, 3);
@@ -58,6 +60,29 @@
add_action('deleted_user_meta', [self::class, 'onUserMetaDelete'], 10, 2);
}
+ public function auth(): static
+ {
+ $this->varyByAuth = true;
+ return $this;
+ }
+
+ public function user(): static
+ {
+ $this->varyByUser = true;
+ return $this;
+ }
+
+ private function resolveKey(int|string $key): string
+ {
+ if ($this->varyByUser) {
+ return $key . ':u' . get_current_user_id();
+ }
+ if ($this->varyByAuth) {
+ return $key . ':' . (is_user_logged_in() ? 'auth' : 'guest');
+ }
+ return (string) $key;
+ }
+
/* ---------------------------------------------------------------------
* Factory
* ------------------------------------------------------------------- */
@@ -358,12 +383,13 @@
?int $ttl = null
): mixed {
if (is_array($key)) {
- $id = $this->generateKey($key);
+ $key = $this->generateKey($key);
}
+ $instanceTags = array_map(fn($tag) => [$this->group, $tag], $this->getTags());
$tags = array_unique(array_merge(
- $this->getTags(),
- array_map('sanitize_key', $tags)
- ));
+ $instanceTags,
+ array_map(fn($tag) => [sanitize_key($tag[0]), $tag[1]], $tags)
+ ), SORT_REGULAR);
$value = wp_cache_get($key, $this->group);
@@ -474,24 +500,24 @@
self::invalidateItem('post', $postId);
}
- public static function onPostMetaChange(int $metaId, int $objectId): void
- {
-// error_log('[Clearing cache for post meta change: '.$objectId.']');
- self::invalidateItem('post', $objectId);
- }
-
- public static function onPostMetaDelete(array $metaIds, int $objectId): void
- {
-// error_log('[Clearing cache for post meta delete: '.$objectId.']');
- self::invalidateItem('post', $objectId);
- }
+// public static function onPostMetaChange(int $metaId, int $objectId): void
+// {
+//// error_log('[Clearing cache for post meta change: '.$objectId.']');
+// self::invalidateItem('post', $objectId);
+// }
+//
+// public static function onPostMetaDelete(array $metaIds, int $objectId): void
+// {
+//// error_log('[Clearing cache for post meta delete: '.$objectId.']');
+// self::invalidateItem('post', $objectId);
+// }
/****************************************************
* HOOKS - Terms
****************************************************/
public static function onTermChange(int $termId, int $ttId, string $taxonomy): void
{
-// error_log('[Clearing cache for term change: '.$termId.']');
+ error_log('[Clearing cache for term change: '.$termId.']');
self::invalidateItem('taxonomy', $termId);
}
--
Gitblit v1.10.0