From de317675a8069b747cb253ba3e2b5dc394ca36ef Mon Sep 17 00:00:00 2001
From: Jake Vanderwerf <get@jakevanderwerf.ca>
Date: Sat, 18 Jul 2026 21:44:51 +0000
Subject: [PATCH] =Base Integrations mainly done - doing a test with setting up the Square integration to follow
---
inc/managers/Cache.php | 37 +++++++++++++++++++++++++++++++++----
1 files changed, 33 insertions(+), 4 deletions(-)
diff --git a/inc/managers/Cache.php b/inc/managers/Cache.php
index 7653b9a..2f62928 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)
{
@@ -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
* ------------------------------------------------------------------- */
@@ -79,6 +104,9 @@
public function remember(int|string|array $key, callable $callback, ?int $ttl = null): mixed
{
+ //TODO: Redis is fucking this all up for some reason. While we figure it out, let's just return the callback
+ return $callback();
+
if (is_array($key)) {
$key = $this->generateKey($key);
}
@@ -358,12 +386,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);
--
Gitblit v1.10.0