=Cache::connects throughout codebase refactored
| | |
| | | class NewsRelationships |
| | | { |
| | | private CustomTable $relationships; |
| | | protected Cache $cache; |
| | | |
| | | public function __construct() |
| | | { |
| | |
| | | { |
| | | 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']); |
| | |
| | | */ |
| | | 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(); |
| | | } |
| | | |
| | | /** |
| | |
| | | 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( |
| | |
| | | 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(); |
| | |
| | | $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': |
| | |
| | | */ |
| | | 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)); |
| | | } |
| | | |
| | |
| | | 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))); |
| | | } |
| | | |
| | |
| | | */ |
| | | 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')); |
| | | } |
| | | |
| | |
| | | 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] = []; |
| | |
| | | */ |
| | | 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); |
| | |
| | | */ |
| | | 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'); |
| | |
| | | } |
| | | |
| | | $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); |
| | |
| | | */ |
| | | 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'); |
| | |
| | | parent::__construct(); |
| | | $this->cache = Cache::for($this->taxonomy, 'term', DAY_IN_SECONDS); |
| | | $this->setupTables(); |
| | | $this->setupCacheConnections(); |
| | | } |
| | | |
| | | add_action('init', [$this, 'registerContentTermsExecutors'], 5); |
| | |
| | | } |
| | | } |
| | | |
| | | protected function setupCacheConnections(): void |
| | | { |
| | | $this->cache |
| | | ->connect('taxonomy') |
| | | ->connect('user'); |
| | | } |
| | | |
| | | public function registerRoutes(): void |
| | | { |
| | | if (!$this->registrar->hasFeature('is_content')) { |
| | |
| | | $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; |
| | | |
| | |
| | | $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; |
| | | |
| | |
| | | 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; |
| | |
| | | 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 |
| | |
| | | } |
| | | |
| | | $args = [ |
| | | 'user' => $userID, |
| | | 'id' => $userID, |
| | | 'to_term' => $termID, |
| | | 'taxonomy' => $taxonomy ? jvbNoBase($taxonomy) : null, |
| | | 'status' => $request->get_param('status'), |
| | |
| | | $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'); |
| | |
| | | { |
| | | $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) { |
| | |
| | | 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) { |