Endpoints/Cache

* fix cache id collision when category == dbTypeId for a given dbType
 * increment version number to invalidate existing caches
 * maps endpoint doesn't need caching. It is entirely static content.
This commit is contained in:
Sarjuuk
2025-10-08 18:20:26 +02:00
parent 95ee9d2c25
commit 3edac3c77a
53 changed files with 61 additions and 68 deletions

View File

@@ -21,7 +21,7 @@ class AchievementBaseResponse extends TemplateResponse implements ICache
{
use TrDetailPage, TrCache;
protected int $cacheType = CACHE_TYPE_PAGE;
protected int $cacheType = CACHE_TYPE_DETAIL_PAGE;
protected string $template = 'achievement';
protected string $pageName = 'achievement';

View File

@@ -11,7 +11,7 @@ class AchievementsBaseResponse extends TemplateResponse implements ICache
use TrListPage, TrCache;
protected int $type = Type::ACHIEVEMENT;
protected int $cacheType = CACHE_TYPE_PAGE;
protected int $cacheType = CACHE_TYPE_LIST_PAGE;
protected string $template = 'achievements';
protected string $pageName = 'achievements';

View File

@@ -10,7 +10,7 @@ class AreatriggerBaseResponse extends TemplateResponse implements ICache
{
use TrDetailPage, TrCache;
protected int $cacheType = CACHE_TYPE_PAGE;
protected int $cacheType = CACHE_TYPE_DETAIL_PAGE;
protected int $requiredUserGroup = U_GROUP_STAFF;
protected string $template = 'detail-page-generic';

View File

@@ -11,7 +11,7 @@ class AreatriggersBaseResponse extends TemplateResponse implements ICache
use TrListPage, TrCache;
protected int $type = Type::AREATRIGGER;
protected int $cacheType = CACHE_TYPE_PAGE;
protected int $cacheType = CACHE_TYPE_LIST_PAGE;
protected int $requiredUserGroup = U_GROUP_STAFF;
protected string $template = 'areatriggers';

View File

@@ -12,7 +12,7 @@ class ClassBaseResponse extends TemplateResponse implements ICache
private const TC_CLASS_IDS = [null, 8, 3, 1, 5, 4, 9, 6, 2, 7, null, 0]; // see TalentCalc.js
protected int $cacheType = CACHE_TYPE_PAGE;
protected int $cacheType = CACHE_TYPE_DETAIL_PAGE;
protected string $template = 'detail-page-generic';
protected string $pageName = 'class';

View File

@@ -11,7 +11,7 @@ class ClassesBaseResponse extends TemplateResponse implements ICache
use TrListPage, TrCache;
protected int $type = Type::CHR_CLASS;
protected int $cacheType = CACHE_TYPE_PAGE;
protected int $cacheType = CACHE_TYPE_LIST_PAGE;
protected string $template = 'list-page-generic';
protected string $pageName = 'classes';

View File

@@ -11,7 +11,7 @@ class CurrenciesBaseResponse extends TemplateResponse implements ICache
use TrListPage, TrCache;
protected int $type = Type::CURRENCY;
protected int $cacheType = CACHE_TYPE_PAGE;
protected int $cacheType = CACHE_TYPE_LIST_PAGE;
protected string $template = 'list-page-generic';
protected string $pageName = 'currencies';

View File

@@ -10,7 +10,7 @@ class CurrencyBaseResponse extends TemplateResponse implements ICache
{
use TrDetailPage, TrCache;
protected int $cacheType = CACHE_TYPE_PAGE;
protected int $cacheType = CACHE_TYPE_DETAIL_PAGE;
protected string $template = 'detail-page-generic';
protected string $pageName = 'currency';

View File

@@ -10,7 +10,7 @@ class EmoteBaseResponse extends TemplateResponse implements ICache
{
use TrDetailPage, TrCache;
protected int $cacheType = CACHE_TYPE_PAGE;
protected int $cacheType = CACHE_TYPE_DETAIL_PAGE;
protected string $template = 'detail-page-generic';
protected string $pageName = 'emote';

View File

@@ -10,7 +10,7 @@ class EmotesBaseResponse extends TemplateResponse implements ICache
{
use TrListPage, TrCache;
protected int $cacheType = CACHE_TYPE_PAGE;
protected int $cacheType = CACHE_TYPE_LIST_PAGE;
protected int $type = Type::EMOTE;
protected string $template = 'list-page-generic';

View File

@@ -10,7 +10,7 @@ class EnchantmentBaseResponse extends TemplateResponse implements ICache
{
use TrDetailPage, TrCache;
protected int $cacheType = CACHE_TYPE_PAGE;
protected int $cacheType = CACHE_TYPE_DETAIL_PAGE;
protected string $template = 'enchantment';
protected string $pageName = 'enchantment';

View File

@@ -11,7 +11,7 @@ class EnchantmentsBaseResponse extends TemplateResponse implements ICache
use TrListPage, TrCache;
protected int $type = Type::ENCHANTMENT;
protected int $cacheType = CACHE_TYPE_PAGE;
protected int $cacheType = CACHE_TYPE_LIST_PAGE;
protected string $template = 'enchantments';
protected string $pageName = 'enchantments';

View File

@@ -10,7 +10,7 @@ class EventBaseResponse extends TemplateResponse implements ICache
{
use TrDetailPage, TrCache;
protected int $cacheType = CACHE_TYPE_PAGE;
protected int $cacheType = CACHE_TYPE_DETAIL_PAGE;
protected string $template = 'detail-page-generic';
protected string $pageName = 'event';

View File

@@ -11,7 +11,7 @@ class EventsBaseResponse extends TemplateResponse implements ICache
use TrListPage, TrCache;
protected int $type = Type::WORLDEVENT;
protected int $cacheType = CACHE_TYPE_PAGE;
protected int $cacheType = CACHE_TYPE_LIST_PAGE;
protected string $template = 'list-page-generic';
protected string $pageName = 'events';

View File

@@ -10,7 +10,7 @@ class FactionBaseResponse extends TemplateResponse implements ICache
{
use TrDetailPage, TrCache;
protected int $cacheType = CACHE_TYPE_PAGE;
protected int $cacheType = CACHE_TYPE_DETAIL_PAGE;
protected string $template = 'detail-page-generic';
protected string $pageName = 'faction';

View File

@@ -11,7 +11,7 @@ class FactionsBaseResponse extends TemplateResponse implements ICache
use TrListPage, TrCache;
protected int $type = Type::FACTION;
protected int $cacheType = CACHE_TYPE_PAGE;
protected int $cacheType = CACHE_TYPE_LIST_PAGE;
protected string $template = 'list-page-generic';
protected string $pageName = 'factions';

View File

@@ -10,7 +10,7 @@ class GuideBaseResponse extends TemplateResponse implements ICache
{
use TrDetailPage, TrCache;
protected int $cacheType = CACHE_TYPE_PAGE;
protected int $cacheType = CACHE_TYPE_DETAIL_PAGE;
protected string $template = 'detail-page-generic';
protected string $pageName = 'guide';

View File

@@ -10,7 +10,7 @@ class GuidesBaseResponse extends TemplateResponse // implements ICache
{
use TrListPage/* , TrCache */;
// protected int $cacheType = CACHE_TYPE_PAGE; // really do? cache would need to be destroyed externally with each guide status update
// protected int $cacheType = CACHE_TYPE_LIST_PAGE; // really do? cache would need to be destroyed externally with each guide status update
protected int $type = Type::GUIDE;
protected string $template = 'list-page-generic';

View File

@@ -10,7 +10,7 @@ class IconBaseResponse extends TemplateResponse implements ICache
{
use TrDetailPage, TrCache;
protected int $cacheType = CACHE_TYPE_PAGE;
protected int $cacheType = CACHE_TYPE_DETAIL_PAGE;
protected string $template = 'icon';
protected string $pageName = 'icon';

View File

@@ -11,7 +11,7 @@ class IconsBaseResponse extends TemplateResponse implements ICache
use TrListPage, TrCache;
protected int $type = Type::ICON;
protected int $cacheType = CACHE_TYPE_PAGE;
protected int $cacheType = CACHE_TYPE_LIST_PAGE;
protected string $template = 'icons';
protected string $pageName = 'icons';

View File

@@ -10,7 +10,7 @@ class ItemBaseResponse extends TemplateResponse implements ICache
{
use TrDetailPage, TrCache;
protected int $cacheType = CACHE_TYPE_PAGE;
protected int $cacheType = CACHE_TYPE_DETAIL_PAGE;
protected string $template = 'item';
protected string $pageName = 'item';

View File

@@ -220,8 +220,7 @@ class ItemXmlResponse extends TextResponse implements ICache
{
return array(
$this->type, // DBType
$this->typeId, // DBTypeId
-1, // category
$this->typeId, // DBTypeId/category
-1, // staff mask (content does not diff)
'' // misc (unused)
);

View File

@@ -11,7 +11,7 @@ class ItemsBaseResponse extends TemplateResponse implements ICache
use TrListPage, TrCache;
protected int $type = Type::ITEM;
protected int $cacheType = CACHE_TYPE_PAGE;
protected int $cacheType = CACHE_TYPE_LIST_PAGE;
protected string $template = 'items';
protected string $pageName = 'items';

View File

@@ -10,7 +10,7 @@ class ItemsetBaseResponse extends TemplateResponse implements ICache
{
use TrDetailPage, TrCache;
protected int $cacheType = CACHE_TYPE_PAGE;
protected int $cacheType = CACHE_TYPE_DETAIL_PAGE;
protected string $template = 'itemset';
protected string $pageName = 'itemset';

View File

@@ -11,7 +11,7 @@ class ItemsetsBaseResponse extends TemplateResponse implements ICache
use TrListPage, TrCache;
protected int $type = Type::ITEMSET;
protected int $cacheType = CACHE_TYPE_PAGE;
protected int $cacheType = CACHE_TYPE_LIST_PAGE;
protected string $template = 'itemsets';
protected string $pageName = 'itemsets';

View File

@@ -10,7 +10,7 @@ class MailBaseResponse extends TemplateResponse implements ICache
{
use TrDetailPage, TrCache;
protected int $cacheType = CACHE_TYPE_PAGE;
protected int $cacheType = CACHE_TYPE_DETAIL_PAGE;
protected string $template = 'detail-page-generic';
protected string $pageName = 'mail';

View File

@@ -11,7 +11,7 @@ class MailsBaseResponse extends TemplateResponse implements ICache
use TrListPage, TrCache;
protected int $type = Type::MAIL;
protected int $cacheType = CACHE_TYPE_PAGE;
protected int $cacheType = CACHE_TYPE_LIST_PAGE;
protected string $template = 'list-page-generic';
protected string $pageName = 'mails';

View File

@@ -8,8 +8,6 @@ if (!defined('AOWOW_REVISION'))
class MapsBaseResponse extends TemplateResponse
{
protected int $cacheType = CACHE_TYPE_PAGE;
protected string $template = 'maps';
protected string $pageName = 'maps';
protected ?int $activeTab = parent::TAB_TOOLS;

View File

@@ -10,7 +10,7 @@ class NpcBaseResponse extends TemplateResponse implements ICache
{
use TrDetailPage, TrCache;
protected int $cacheType = CACHE_TYPE_PAGE;
protected int $cacheType = CACHE_TYPE_DETAIL_PAGE;
protected string $template = 'npc';
protected string $pageName = 'npc';

View File

@@ -11,7 +11,7 @@ class NpcsBaseResponse extends TemplateResponse implements ICache
use TrListPage, TrCache;
protected int $type = Type::NPC;
protected int $cacheType = CACHE_TYPE_PAGE;
protected int $cacheType = CACHE_TYPE_LIST_PAGE;
protected string $template = 'npcs';
protected string $pageName = 'npcs';

View File

@@ -10,7 +10,7 @@ class ObjectBaseResponse extends TemplateResponse implements ICache
{
use TrDetailPage, TrCache;
protected int $cacheType = CACHE_TYPE_PAGE;
protected int $cacheType = CACHE_TYPE_DETAIL_PAGE;
protected string $template = 'object';
protected string $pageName = 'object';

View File

@@ -11,7 +11,7 @@ class ObjectsBaseResponse extends TemplateResponse implements ICache
use TrListPage, TrCache;
protected int $type = Type::OBJECT;
protected int $cacheType = CACHE_TYPE_PAGE;
protected int $cacheType = CACHE_TYPE_LIST_PAGE;
protected string $template = 'objects';
protected string $pageName = 'objects';

View File

@@ -10,7 +10,7 @@ class PetBaseResponse extends TemplateResponse implements ICache
{
use TrDetailPage, TrCache;
protected int $cacheType = CACHE_TYPE_PAGE;
protected int $cacheType = CACHE_TYPE_DETAIL_PAGE;
protected string $template = 'detail-page-generic';
protected string $pageName = 'pet';

View File

@@ -11,7 +11,7 @@ class PetsBaseResponse extends TemplateResponse implements ICache
use TrListPage, TrCache;
protected int $type = Type::PET;
protected int $cacheType = CACHE_TYPE_PAGE;
protected int $cacheType = CACHE_TYPE_LIST_PAGE;
protected string $template = 'list-page-generic';
protected string $pageName = 'pets';

View File

@@ -10,7 +10,7 @@ class QuestBaseResponse extends TemplateResponse implements ICache
{
use TrDetailPage, TrCache;
protected int $cacheType = CACHE_TYPE_PAGE;
protected int $cacheType = CACHE_TYPE_DETAIL_PAGE;
protected string $template = 'quest';
protected string $pageName = 'quest';

View File

@@ -32,7 +32,7 @@ class QuestsBaseResponse extends TemplateResponse implements ICache
);
protected int $type = Type::QUEST;
protected int $cacheType = CACHE_TYPE_PAGE;
protected int $cacheType = CACHE_TYPE_LIST_PAGE;
protected string $template = 'quests';
protected string $pageName = 'quests';

View File

@@ -16,7 +16,7 @@ class RaceBaseResponse extends TemplateResponse implements ICache
[7952, 33554], null, [16264, 33557], [17584, 33657]
);
protected int $cacheType = CACHE_TYPE_PAGE;
protected int $cacheType = CACHE_TYPE_DETAIL_PAGE;
protected string $template = 'detail-page-generic';
protected string $pageName = 'race';

View File

@@ -11,7 +11,7 @@ class RacesBaseResponse extends TemplateResponse implements ICache
use TrListPage, TrCache;
protected int $type = Type::CHR_RACE;
protected int $cacheType = CACHE_TYPE_PAGE;
protected int $cacheType = CACHE_TYPE_LIST_PAGE;
protected string $template = 'list-page-generic';
protected string $pageName = 'races';

View File

@@ -10,7 +10,7 @@ class SkillBaseResponse extends TemplateResponse implements ICache
{
use TrDetailPage, TrCache;
protected int $cacheType = CACHE_TYPE_PAGE;
protected int $cacheType = CACHE_TYPE_DETAIL_PAGE;
protected string $template = 'detail-page-generic';
protected string $pageName = 'skill';

View File

@@ -11,7 +11,7 @@ class SkillsBaseResponse extends TemplateResponse implements ICache
use TrListPage, TrCache;
protected int $type = Type::SKILL;
protected int $cacheType = CACHE_TYPE_PAGE;
protected int $cacheType = CACHE_TYPE_LIST_PAGE;
protected string $template = 'list-page-generic';
protected string $pageName = 'skills';

View File

@@ -10,7 +10,7 @@ class SoundBaseResponse extends TemplateResponse implements ICache
{
use TrDetailPage, TrCache;
protected int $cacheType = CACHE_TYPE_PAGE;
protected int $cacheType = CACHE_TYPE_DETAIL_PAGE;
protected string $template = 'sound';
protected string $pageName = 'sound';

View File

@@ -11,7 +11,7 @@ class SoundsBaseResponse extends TemplateResponse implements ICache
use TrListPage, TrCache;
protected int $type = Type::SOUND;
protected int $cacheType = CACHE_TYPE_PAGE;
protected int $cacheType = CACHE_TYPE_LIST_PAGE;
protected string $template = 'sounds';
protected string $pageName = 'sounds';

View File

@@ -16,7 +16,7 @@ class SpellBaseResponse extends TemplateResponse implements ICache
SPELL_AURA_MOD_IGNORE_SHAPESHIFT, SPELL_AURA_PERIODIC_HASTE, SPELL_AURA_OVERRIDE_CLASS_SCRIPTS,
SPELL_AURA_MOD_DAMAGE_FROM_CASTER, SPELL_AURA_ADD_TARGET_TRIGGER, /* SPELL_AURA_DUMMY ? */];
protected int $cacheType = CACHE_TYPE_PAGE;
protected int $cacheType = CACHE_TYPE_DETAIL_PAGE;
protected string $template = 'spell';
protected string $pageName = 'spell';

View File

@@ -26,7 +26,7 @@ class SpellsBaseResponse extends TemplateResponse implements ICache
);
protected int $type = Type::SPELL;
protected int $cacheType = CACHE_TYPE_PAGE;
protected int $cacheType = CACHE_TYPE_LIST_PAGE;
protected string $template = 'spells';
protected string $pageName = 'spells';

View File

@@ -10,7 +10,7 @@ class TitleBaseResponse extends TemplateResponse implements ICache
{
use TrDetailPage, TrCache;
protected int $cacheType = CACHE_TYPE_PAGE;
protected int $cacheType = CACHE_TYPE_DETAIL_PAGE;
protected string $template = 'detail-page-generic';
protected array $breadcrumb = [0, 10];

View File

@@ -11,7 +11,7 @@ class TitlesBaseResponse extends TemplateResponse implements ICache
use TrListPage, TrCache;
protected int $type = Type::TITLE;
protected int $cacheType = CACHE_TYPE_PAGE;
protected int $cacheType = CACHE_TYPE_LIST_PAGE;
protected string $template = 'list-page-generic';
protected string $pageName = 'titles';

View File

@@ -10,7 +10,7 @@ class ZoneBaseResponse extends TemplateResponse implements ICache
{
use TrDetailPage, TrCache;
protected int $cacheType = CACHE_TYPE_PAGE;
protected int $cacheType = CACHE_TYPE_DETAIL_PAGE;
protected string $template = 'detail-page-generic';
protected string $pageName = 'zone';

View File

@@ -11,7 +11,7 @@ class ZonesBaseResponse extends TemplateResponse implements ICache
use TrListPage, TrCache;
protected int $type = Type::ZONE;
protected int $cacheType = CACHE_TYPE_PAGE;
protected int $cacheType = CACHE_TYPE_LIST_PAGE;
protected string $template = 'list-page-generic';
protected string $pageName = 'zones';

View File

@@ -201,9 +201,9 @@ trait TrCache
{
$this->initCache();
// type+typeId+catg; 3+6+10
// type+typeId/catg+mode; 3+10+1
$cKey = $this->formatCacheKey();
$cKey[2] = substr($cKey[2], 0, 19);
$cKey[2] = substr($cKey[2], 0, 13);
if ($modeMask & CACHE_MODE_MEMCACHED)
foreach ($this->memcached()?->getAllKeys() ?? [] as $k)
@@ -265,29 +265,27 @@ trait TrCache
// https://stackoverflow.com/questions/466521
private function formatCacheKey() : array
{
[$dbType, $dbTypeId, $category, $staffMask, $miscInfo] = $this->getCacheKeyComponents();
[$dbType, $dbTypeIdOrCat, $staffMask, $miscInfo] = $this->getCacheKeyComponents();
$fileKey = '';
// DBType: 3
$fileKey .= str_pad(dechex($dbType & 0xFFF), 3, 0, STR_PAD_LEFT);
// DBTypeId: 6
$fileKey .= str_pad(dechex($dbTypeId & 0xFFFFFF), 6, 0, STR_PAD_LEFT);
// category: (2+4+4)
$fileKey .= str_pad(dechex($category & 0xFFFFFFFFFF), 2+4+4, 0, STR_PAD_LEFT);
// DBTypeId: 6 / category: (2+4+4)
$fileKey .= str_pad(dechex($dbTypeIdOrCat & 0xFFFFFFFFFF), 2+4+4, 0, STR_PAD_LEFT);
// cacheType: 1
$fileKey .= str_pad(dechex($this->_cacheType & 0xF), 1, 0, STR_PAD_LEFT);
// localeId: 2,
$fileKey .= str_pad(dechex(Lang::getLocale()->value & 0xFF), 2, 0, STR_PAD_LEFT);
// staff mask: 4
$fileKey .= str_pad(dechex($staffMask & 0xFFFFFFFF), 4, 0, STR_PAD_LEFT);
// optioal: miscInfo
// optional: miscInfo
if ($miscInfo)
$fileKey .= '-'.$miscInfo;
// topDir, 2ndDir, file
return array(
str_pad(dechex($dbType & 0xFF), 2, 0, STR_PAD_LEFT),
str_pad(dechex(($dbTypeId > 0 ? $dbTypeId : $category) & 0xFF), 2, 0, STR_PAD_LEFT),
str_pad(dechex(($dbTypeIdOrCat) & 0xFF), 2, 0, STR_PAD_LEFT),
$fileKey
);
}
@@ -327,8 +325,7 @@ trait TrSearch
{
return array(
-1, // DBType
-1, // DBTypeId
$this->searchMask, // category
$this->searchMask, // DBTypeId/category
User::$groups, // staff mask
md5($this->query) // misc (here search query)
);

View File

@@ -21,8 +21,7 @@ trait TrDetailPage
{
return array(
$this->type, // DBType
$this->typeId, // DBTypeId
-1, // category
$this->typeId, // DBTypeId/category
User::$groups, // staff mask
'' // misc (here unused)
);
@@ -54,8 +53,7 @@ trait TrListPage
return array(
$this->type, // DBType
-1, // DBTypeId
$catg ?? -1, // category
$catg ?? -1, // DBTypeId/category
User::$groups, // staff mask
$misc ?? '' // misc (here filter)
);

View File

@@ -14,8 +14,7 @@ trait TrTooltip
{
$key = array(
$this->type, // DBType
$this->typeId, // DBTypeId
-1, // category
$this->typeId, // DBTypeId/category
User::$groups, // staff mask
'' // misc (here tooltip)
);

View File

@@ -41,6 +41,8 @@ define('CACHE_TYPE_PAGE', 1);
define('CACHE_TYPE_TOOLTIP', 2);
define('CACHE_TYPE_SEARCH', 3);
define('CACHE_TYPE_XML', 4); // only used by items
define('CACHE_TYPE_LIST_PAGE', 5);
define('CACHE_TYPE_DETAIL_PAGE', 6);
define('CACHE_MODE_FILECACHE', 0x1);
define('CACHE_MODE_MEMCACHED', 0x2);

View File

@@ -6,7 +6,7 @@ mb_internal_encoding('UTF-8');
error_reporting(E_ALL);
mysqli_report(MYSQLI_REPORT_ERROR);
define('AOWOW_REVISION', 41);
define('AOWOW_REVISION', 42);
define('OS_WIN', substr(PHP_OS, 0, 3) == 'WIN'); // OS_WIN as per compile info of php
define('CLI', PHP_SAPI === 'cli');
define('CLI_HAS_E', CLI && // WIN10 and later usually support ANSI escape sequences