Skip to content

Instantly share code, notes, and snippets.

@o1y
Last active January 29, 2023 19:26
Show Gist options
  • Select an option

  • Save o1y/6158c7addb65ec27835dc24bcf96b693 to your computer and use it in GitHub Desktop.

Select an option

Save o1y/6158c7addb65ec27835dc24bcf96b693 to your computer and use it in GitHub Desktop.
Statamic Performance Experiment

This is a patch from PR3984 without any tests included.

  1. composer require cweagans/composer-patches
  2. Change your composer.json with the following content and run composer install
"extra": {
  "patches": {
    "statamic/cms": {
      "Store/Get items in/from Blink instead of always calling from Cache": "https://gist.githubusercontent.com/o1y/6158c7addb65ec27835dc24bcf96b693/raw/2d22edbff2a4fdfdc63756d7a2803f15a2668fe6/PR3984.patch"
    }
  }
},
diff --git a/src/Stache/Stores/BasicStore.php b/src/Stache/Stores/BasicStore.php
index 07d8f7288e..c10660ba2f 100644
--- a/src/Stache/Stores/BasicStore.php
+++ b/src/Stache/Stores/BasicStore.php
@@ -3,6 +3,7 @@
namespace Statamic\Stache\Stores;
use Illuminate\Support\Facades\Cache;
+use Statamic\Facades\Blink;
use Statamic\Facades\File;
use Symfony\Component\Finder\SplFileInfo;
@@ -43,7 +44,9 @@ protected function getCachedItem($key)
{
$cacheKey = $this->getItemCacheKey($key);
- return Cache::get($cacheKey);
+ return Blink::once($cacheKey, function () use ($cacheKey) {
+ return Cache::get($cacheKey);
+ });
}
protected function cacheItem($item)
diff --git a/src/Stache/Stores/BasicStore.php b/src/Stache/Stores/BasicStore.php
index c10660ba2f..07baf03c69 100644
--- a/src/Stache/Stores/BasicStore.php
+++ b/src/Stache/Stores/BasicStore.php
@@ -55,11 +55,13 @@ protected function cacheItem($item)
$cacheKey = $this->getItemCacheKey($key);
+ Blink::forget($cacheKey);
Cache::forever($cacheKey, $item);
}
public function forgetItem($key)
{
+ Blink::forget($this->getItemCacheKey($key));
Cache::forget($this->getItemCacheKey($key));
}
diff --git a/src/Stache/Stores/BasicStore.php b/src/Stache/Stores/BasicStore.php
index 07baf03c69..8452894d24 100644
--- a/src/Stache/Stores/BasicStore.php
+++ b/src/Stache/Stores/BasicStore.php
@@ -55,7 +55,7 @@ protected function cacheItem($item)
$cacheKey = $this->getItemCacheKey($key);
- Blink::forget($cacheKey);
+ Blink::put($cacheKey, $item);
Cache::forever($cacheKey, $item);
}
diff --git a/src/Stache/Repositories/TaxonomyRepository.php b/src/Stache/Repositories/TaxonomyRepository.php
index a4d0cfee8c..166b7f29d0 100644
--- a/src/Stache/Repositories/TaxonomyRepository.php
+++ b/src/Stache/Repositories/TaxonomyRepository.php
@@ -45,6 +45,8 @@ public function findByHandle($handle): ?Taxonomy
public function save(Taxonomy $taxonomy)
{
+ Facades\Blink::forget('taxonomy-'.$taxonomy->handle());
+
$this->store->save($taxonomy);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment