Skip to content

Commit

Permalink
FEAT less cache fragmentation
Browse files Browse the repository at this point in the history
implements #11525
  • Loading branch information
lekoala authored Jan 7, 2025
1 parent f3c3bbc commit 6f6c780
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/Core/Manifest/ClassManifest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,19 @@ class ClassManifest
*/
protected $cacheKey;

/**
* In memory cache array for individually parsed files
* @var array|null
*/
protected ?array $filesCache = null;

/**
* Key to use for files cache
*
* @var string
*/
protected string $filesCacheKey;

/**
* Array of properties to cache
*
Expand Down Expand Up @@ -203,6 +216,7 @@ public function __construct($base, CacheFactory $cacheFactory = null)
$this->base = $base;
$this->cacheFactory = $cacheFactory;
$this->cacheKey = 'manifest';
$this->filesCacheKey = 'manifestFiles';
}

private function buildCache($includeTests = false)
Expand Down Expand Up @@ -563,6 +577,7 @@ public function regenerate($includeTests)

if ($this->cache) {
$data = $this->getState();
$this->cache->set($this->filesCacheKey, $this->filesCache);
$this->cache->set($this->cacheKey, $data);
$this->cache->set('generated_at', time());
$this->cache->delete('regenerate');
Expand All @@ -587,6 +602,10 @@ public function handleFile($basename, $pathname, $includeTests)
// since just using the datetime lead to problems with upgrading.
$key = preg_replace('/[^a-zA-Z0-9_]/', '_', $basename ?? '') . '_' . md5_file($pathname ?? '');

if ($this->cache && $this->filesCache === null) {
$this->filesCache = $this->cache->get($this->filesCacheKey);
}

// Attempt to load from cache
// Note: $classes, $interfaces and $traits arrays have correct-case keys, not lowercase
$changed = false;
Expand Down Expand Up @@ -696,8 +715,10 @@ public function handleFile($basename, $pathname, $includeTests)
'classes' => $classes,
'interfaces' => $interfaces,
'traits' => $traits,
'enums' => $enums,
];
$this->cache->set($key, $cache);

$this->filesCache[$key] = $cache;
}
}

Expand Down

0 comments on commit 6f6c780

Please sign in to comment.