From 670af92c863211fcaa8f229b0a83d36410e83257 Mon Sep 17 00:00:00 2001 From: Awilum Date: Sun, 1 May 2022 15:55:26 +0300 Subject: [PATCH] feat(entries): add ability to set salt for cache id --- src/flextype/core/Entries/Entries.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/flextype/core/Entries/Entries.php b/src/flextype/core/Entries/Entries.php index c7a48d9e..fcb092fb 100755 --- a/src/flextype/core/Entries/Entries.php +++ b/src/flextype/core/Entries/Entries.php @@ -222,7 +222,7 @@ class Entries if (! is_null($this->registry()->get('methods.fetch.result'))) { return $this->registry()->get('methods.fetch.result'); } - + // Single fetch helper $single = function ($id, $options) { @@ -245,7 +245,7 @@ class Entries } // Get Cache ID for current requested entry - $entryCacheID = $this->getCacheID($this->registry()->get('methods.fetch.params.id')); + $entryCacheID = $this->getCacheID($this->registry()->get('methods.fetch.params.id'), 'single'); // 1. Try to get current requested entry from the cache. if (cache()->has($entryCacheID)) { @@ -786,19 +786,21 @@ class Entries /** * Get Cache ID for entry. * - * @param string $id Unique identifier of the entry. + * @param string $id Unique identifier of the Cache Entry Item. + * @param string $salt Salt to append to the Cache ID. * * @return string Cache ID. * * @access public */ - public function getCacheID(string $id): string + public function getCacheID(string $id, string $salt = ''): string { // Setup registry. $this->registry()->set('methods.getCacheID', [ 'collection' => $this->getCollectionOptions($id), 'params' => [ 'id' => $id, + 'salt' => $salt, ], 'result' => null, ]); @@ -818,10 +820,10 @@ class Entries $entryFile = $this->getFileLocation($this->registry()->get('methods.getCacheID.params.id')); if (filesystem()->file($entryFile)->exists()) { - return strings($this->options['directory'] . $entryFile . (filesystem()->file($entryFile)->lastModified() ?: ''))->hash()->toString(); + return strings($this->options['directory'] . $entryFile . $salt . (filesystem()->file($entryFile)->lastModified() ?: ''))->hash()->toString(); } - return strings($this->options['directory'] . $entryFile)->hash()->toString(); + return strings($this->options['directory'] . $entryFile . $salt)->hash()->toString(); } /**