| | |
| | | class NewsRelationships |
| | | { |
| | | private string $table_name; |
| | | private object $cache; |
| | | private CacheManager $cache; |
| | | |
| | | public function __construct() |
| | | { |
| | | global $wpdb; |
| | | $this->table_name = $wpdb->prefix . BASE . 'news_relationships'; |
| | | $this->cache = new CacheManager('news_relationships', 3600); // 1 hour cache by default |
| | | $this->cache = CacheManager::for('news_relationships', WEEK_IN_SECONDS); |
| | | |
| | | // Register hooks |
| | | add_action('init', [$this, 'registerHooks']); |
| | |
| | | } |
| | | |
| | | // Update cache |
| | | $this->cache->invalidate('shop_' . $shop_id); |
| | | $this->cache->delete($shop_id); |
| | | |
| | | // Update shop total count |
| | | $this->updateShopTotal($shop_id); |
| | |
| | | ); |
| | | |
| | | // Update cache |
| | | $this->cache->invalidate('shop_' . $shop_id); |
| | | $this->cache->delete($shop_id); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | public function getShopNewsStats(int $shop_id):array |
| | | { |
| | | $cache_key = 'shop_' . $shop_id; |
| | | $cached = $this->cache->get($cache_key); |
| | | $cached = $this->cache->get($shop_id); |
| | | |
| | | if ($cached !== false) { |
| | | return $cached; |
| | |
| | | 'artists' => $stats |
| | | ]; |
| | | |
| | | $this->cache->set($cache_key, $result); |
| | | $this->cache->set($shop_id, $result); |
| | | |
| | | return $result; |
| | | } |
| | |
| | | */ |
| | | public function getAllShopsNews():array |
| | | { |
| | | $cache_key = 'all_shops_counts'; |
| | | $cache_key = 'all'; |
| | | $cached = $this->cache->get($cache_key); |
| | | |
| | | if ($cached !== false) { |