From 556ef47d59e2f355ed55df6214027bb11a4f82c8 Mon Sep 17 00:00:00 2001
From: slawkens <slawkens@gmail.com>
Date: Sat, 11 Nov 2023 12:04:21 +0100
Subject: [PATCH] Towns & NPCs & Items should be persistent

---
 .gitignore                         | 1 +
 system/cache/persistent/index.html | 0
 system/functions.php               | 2 +-
 system/libs/DataLoader.php         | 2 +-
 system/libs/Towns.php              | 2 +-
 system/libs/items.php              | 4 ++--
 system/libs/npc.php                | 4 ++--
 7 files changed, 8 insertions(+), 7 deletions(-)
 create mode 100644 system/cache/persistent/index.html

diff --git a/.gitignore b/.gitignore
index b4d564e9..e776e460 100644
--- a/.gitignore
+++ b/.gitignore
@@ -47,6 +47,7 @@ system/cache/*
 !system/cache/twig/index.html
 !system/cache/signatures/index.html
 !system/cache/plugins/index.html
+!system/cache/persistent/index.html
 
 # logs
 system/logs/*
diff --git a/system/cache/persistent/index.html b/system/cache/persistent/index.html
new file mode 100644
index 00000000..e69de29b
diff --git a/system/functions.php b/system/functions.php
index afa5e969..bfd113b7 100644
--- a/system/functions.php
+++ b/system/functions.php
@@ -1262,7 +1262,7 @@ function clearCache()
 	deleteDirectory(CACHE . 'signatures', ['index.html'], true);
 	deleteDirectory(CACHE . 'twig', ['index.html'], true);
 	deleteDirectory(CACHE . 'plugins', ['index.html'], true);
-	deleteDirectory(CACHE, ['signatures', 'twig', 'plugins', 'index.html'], true);
+	deleteDirectory(CACHE, ['signatures', 'twig', 'plugins', 'index.html', 'persistent'], true);
 
 	// routes cache
 	$routeCacheFile = CACHE . 'route.cache';
diff --git a/system/libs/DataLoader.php b/system/libs/DataLoader.php
index 66b4ed27..85245a6b 100644
--- a/system/libs/DataLoader.php
+++ b/system/libs/DataLoader.php
@@ -38,7 +38,7 @@ class DataLoader
 	{
 		self::$startTime = microtime(true);
 
-		require LIBS . 'items.php';
+		require_once LIBS . 'items.php';
 		if(Items::loadFromXML()) {
 			success(self::$locale['step_database_loaded_items'] . self::getLoadedTime());
 		}
diff --git a/system/libs/Towns.php b/system/libs/Towns.php
index d528118a..f13e1025 100644
--- a/system/libs/Towns.php
+++ b/system/libs/Towns.php
@@ -33,7 +33,7 @@ class Towns
 	/**
 	 * @var string
 	 */
-	private static $filename = CACHE . 'towns.php';
+	private static $filename = CACHE . 'persistent' . 'towns.php';
 
 	/**
 	 * Determine towns
diff --git a/system/libs/items.php b/system/libs/items.php
index d90eff6b..2c29faf5 100644
--- a/system/libs/items.php
+++ b/system/libs/items.php
@@ -40,7 +40,7 @@ class Items
 		}
 
 		require_once LIBS . 'cache_php.php';
-		$cache_php = new Cache_PHP(config('cache_prefix'), CACHE);
+		$cache_php = new Cache_PHP(config('cache_prefix'), CACHE . 'persistent');
 		$cache_php->set('items', $items, 5 * 365 * 24 * 60 * 60);
 		return true;
 	}
@@ -68,7 +68,7 @@ class Items
 		}
 
 		require_once LIBS . 'cache_php.php';
-		$cache_php = new Cache_PHP(config('cache_prefix'), CACHE);
+		$cache_php = new Cache_PHP(config('cache_prefix'), CACHE . 'persistent');
 		self::$items = $cache_php->get('items');
 	}
 
diff --git a/system/libs/npc.php b/system/libs/npc.php
index 3229830e..4d8c7562 100644
--- a/system/libs/npc.php
+++ b/system/libs/npc.php
@@ -41,7 +41,7 @@ class NPCs
 		}
 
 		require_once LIBS . 'cache_php.php';
-		$cache_php = new Cache_PHP(config('cache_prefix'), CACHE);
+		$cache_php = new Cache_PHP(config('cache_prefix'), CACHE . 'persistent');
 		$cache_php->set('npcs', $npcs, 5 * 365 * 24 * 60 * 60);
 		return true;
 	}
@@ -53,7 +53,7 @@ class NPCs
 		}
 
 		require_once LIBS . 'cache_php.php';
-		$cache_php = new Cache_PHP(config('cache_prefix'), CACHE);
+		$cache_php = new Cache_PHP(config('cache_prefix'), CACHE . 'persistent');
 		self::$npcs = $cache_php->get('npcs');
 	}
 }