diff --git a/src/API.php b/src/API.php index f9baae0..29c2e4a 100644 --- a/src/API.php +++ b/src/API.php @@ -82,6 +82,12 @@ class API { */ private $session; + /** + * Key used to cache the session. + * @var string + */ + private $cacheKey = "reflex:paladins:session"; + /** * Getter method for Dev Id * @return int @@ -113,6 +119,13 @@ public function getCache() { return $this->cache; } + /** + * @return string + */ + public function getCacheKey() { + return $this->cacheKey; + } + /** * @return Session */ @@ -222,7 +235,7 @@ public function request($method) { // check validity of session and create if needed if ($request->requiresSession() && (!$this->session || $this->session->isExpired())) { - $this->session = new Session($this); + $this->session = new Session($this, $this->getCacheKey()); } // get all extra args diff --git a/src/Session.php b/src/Session.php index a0a3a60..54b99f6 100644 --- a/src/Session.php +++ b/src/Session.php @@ -8,10 +8,9 @@ class Session { /** - * Change this to use a different key scheme for caching * @var string */ - public static $cachingKey = 'curse:paladins:session'; + public $cacheKey; /** * Timestamp when session was created @@ -28,9 +27,9 @@ class Session { /** * @param API $api */ - function __construct(API $api) { + function __construct(API $api, $cacheKey) { $this->api = $api; - self::$cachingKey = self::$cachingKey . ':' . md5($api->getPlatform()); + $this->cacheKey = $cacheKey . ':' . md5($api->getPlatform()); if (!$this->loadFromCache()) { $this->createSession(); } @@ -67,7 +66,7 @@ private function loadFromCache() { if (!$this->api->getCache()) { return false; } - $data = $this->api->getCache()->fetch(self::$cachingKey); + $data = $this->api->getCache()->fetch($this->cacheKey); if ($data) { list($this->sessionKey, $this->sessionTimestamp) = unserialize($data); return !$this->isExpired(); @@ -85,7 +84,7 @@ private function saveToCache() { } $data = serialize([$this->sessionKey, $this->sessionTimestamp]); // save for 15 minutes - $this->api->getCache()->save(self::$cachingKey, $data, $this->api->sessionTTL()); + $this->api->getCache()->save($this->cacheKey, $data, $this->api->sessionTTL()); } /**