Skip to content

Commit

Permalink
features: CachePlugin and CacheStrategy are now interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
Spomky committed Mar 21, 2024
1 parent 002ad3f commit 02f81ec
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/CachingStrategy/WorkboxCacheStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,24 +140,24 @@ public function render(string $cacheObjectName, bool $debug = false): string
// Needs Workbox: {$this->needsWorkbox()}
// Method: {$this->method}
// 1. Creation of the Workbox Cache Strategy object
// 2. Register the route with the Workbox Router
// 3. Add the assets to the cache when the service worker is installed
DEBUG_STATEMENT;
}

$declaration .= <<<ROUTE_REGISTRATION
// Creation of the Workbox Cache Strategy object
const {$cacheObjectName} = new workbox.strategies.{$this->strategy}({
{$timeout}{$cacheName}plugins: {$plugins}
});
// Register the route with the Workbox Router
workbox.routing.registerRoute({$this->matchCallback},{$cacheObjectName}{$method});
ROUTE_REGISTRATION;

if ($this->preloadUrls !== []) {
$fontUrls = json_encode($this->preloadUrls, $jsonOptions);
$declaration .= <<<ASSET_CACHE_RULE_PRELOAD
// As preloading is enabled, we will add the following assets to the cache when the service worker is installed
self.addEventListener('install', event => {
const done = {$fontUrls}.map(
path =>
Expand All @@ -173,12 +173,14 @@ public function render(string $cacheObjectName, bool $debug = false): string
ASSET_CACHE_RULE_PRELOAD;
}

$declaration .= <<<DEBUG_STATEMENT
if ($debug === true) {
$declaration .= <<<DEBUG_STATEMENT
/**************************************************** END CACHE STRATEGY ****************************************************/
DEBUG_STATEMENT;
}

return $debug === true ? $declaration : trim($declaration);
}
Expand Down
1 change: 1 addition & 0 deletions src/ServiceWorkerRule/ClearCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public function process(bool $debug = false): string
/**************************************************** CACHE CLEAR ****************************************************/
// The configuration is set to clear the cache on each install event
// The following code will remove all the caches
DEBUG_COMMENT;
}

Expand Down

0 comments on commit 02f81ec

Please sign in to comment.