Skip to content

Commit

Permalink
Better cache configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
Spomky committed Mar 5, 2024
1 parent 2f15eb0 commit 5ba6f35
Show file tree
Hide file tree
Showing 10 changed files with 568 additions and 142 deletions.
133 changes: 124 additions & 9 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,8 @@ parameters:
path: src/Dto/Widget.php

-
message: "#^Attribute class JetBrains\\\\PhpStorm\\\\Deprecated does not exist\\.$#"
count: 4
message: "#^Class SpomkyLabs\\\\PwaBundle\\\\Dto\\\\Workbox has an uninitialized property \\$assetCache\\. Give it default value or assign it in the constructor\\.$#"
count: 1
path: src/Dto/Workbox.php

-
Expand All @@ -306,37 +306,37 @@ parameters:
path: src/Dto/Workbox.php

-
message: "#^Class SpomkyLabs\\\\PwaBundle\\\\Dto\\\\Workbox has an uninitialized property \\$googleFontCache\\. Give it default value or assign it in the constructor\\.$#"
message: "#^Class SpomkyLabs\\\\PwaBundle\\\\Dto\\\\Workbox has an uninitialized property \\$fontCache\\. Give it default value or assign it in the constructor\\.$#"
count: 1
path: src/Dto/Workbox.php

-
message: "#^Class SpomkyLabs\\\\PwaBundle\\\\Dto\\\\Workbox has an uninitialized property \\$offlineFallbackPlaceholder\\. Give it default value or assign it in the constructor\\.$#"
message: "#^Class SpomkyLabs\\\\PwaBundle\\\\Dto\\\\Workbox has an uninitialized property \\$googleFontCache\\. Give it default value or assign it in the constructor\\.$#"
count: 1
path: src/Dto/Workbox.php

-
message: "#^Class SpomkyLabs\\\\PwaBundle\\\\Dto\\\\Workbox has an uninitialized property \\$standardRulesPlaceholder\\. Give it default value or assign it in the constructor\\.$#"
message: "#^Class SpomkyLabs\\\\PwaBundle\\\\Dto\\\\Workbox has an uninitialized property \\$imageCache\\. Give it default value or assign it in the constructor\\.$#"
count: 1
path: src/Dto/Workbox.php

-
message: "#^Class SpomkyLabs\\\\PwaBundle\\\\Dto\\\\Workbox has an uninitialized property \\$useCDN\\. Give it default value or assign it in the constructor\\.$#"
message: "#^Class SpomkyLabs\\\\PwaBundle\\\\Dto\\\\Workbox has an uninitialized property \\$offlineFallback\\. Give it default value or assign it in the constructor\\.$#"
count: 1
path: src/Dto/Workbox.php

-
message: "#^Class SpomkyLabs\\\\PwaBundle\\\\Dto\\\\Workbox has an uninitialized property \\$version\\. Give it default value or assign it in the constructor\\.$#"
message: "#^Class SpomkyLabs\\\\PwaBundle\\\\Dto\\\\Workbox has an uninitialized property \\$pageCache\\. Give it default value or assign it in the constructor\\.$#"
count: 1
path: src/Dto/Workbox.php

-
message: "#^Class SpomkyLabs\\\\PwaBundle\\\\Dto\\\\Workbox has an uninitialized property \\$widgetsPlaceholder\\. Give it default value or assign it in the constructor\\.$#"
message: "#^Class SpomkyLabs\\\\PwaBundle\\\\Dto\\\\Workbox has an uninitialized property \\$useCDN\\. Give it default value or assign it in the constructor\\.$#"
count: 1
path: src/Dto/Workbox.php

-
message: "#^Class SpomkyLabs\\\\PwaBundle\\\\Dto\\\\Workbox has an uninitialized property \\$workboxImportPlaceholder\\. Give it default value or assign it in the constructor\\.$#"
message: "#^Class SpomkyLabs\\\\PwaBundle\\\\Dto\\\\Workbox has an uninitialized property \\$version\\. Give it default value or assign it in the constructor\\.$#"
count: 1
path: src/Dto/Workbox.php

Expand Down Expand Up @@ -475,11 +475,126 @@ parameters:
count: 1
path: src/Resources/config/definition/path_type_reference.php

-
message: "#^Anonymous function should return array but returns mixed\\.$#"
count: 10
path: src/Resources/config/definition/service_worker.php

-
message: "#^Call to an undefined method Symfony\\\\Component\\\\Config\\\\Definition\\\\Builder\\\\NodeDefinition\\:\\:children\\(\\)\\.$#"
count: 1
path: src/Resources/config/definition/service_worker.php

-
message: "#^Cannot access offset 'asset_cache' on mixed\\.$#"
count: 2
path: src/Resources/config/definition/service_worker.php

-
message: "#^Cannot access offset 'asset_cache_name' on mixed\\.$#"
count: 1
path: src/Resources/config/definition/service_worker.php

-
message: "#^Cannot access offset 'font_cache' on mixed\\.$#"
count: 2
path: src/Resources/config/definition/service_worker.php

-
message: "#^Cannot access offset 'font_cache_name' on mixed\\.$#"
count: 1
path: src/Resources/config/definition/service_worker.php

-
message: "#^Cannot access offset 'font_fallback' on mixed\\.$#"
count: 1
path: src/Resources/config/definition/service_worker.php

-
message: "#^Cannot access offset 'font_regex' on mixed\\.$#"
count: 1
path: src/Resources/config/definition/service_worker.php

-
message: "#^Cannot access offset 'image_cache' on mixed\\.$#"
count: 2
path: src/Resources/config/definition/service_worker.php

-
message: "#^Cannot access offset 'image_cache_name' on mixed\\.$#"
count: 1
path: src/Resources/config/definition/service_worker.php

-
message: "#^Cannot access offset 'image_fallback' on mixed\\.$#"
count: 1
path: src/Resources/config/definition/service_worker.php

-
message: "#^Cannot access offset 'image_regex' on mixed\\.$#"
count: 1
path: src/Resources/config/definition/service_worker.php

-
message: "#^Cannot access offset 'max_font_age' on mixed\\.$#"
count: 1
path: src/Resources/config/definition/service_worker.php

-
message: "#^Cannot access offset 'max_font_cache…' on mixed\\.$#"
count: 1
path: src/Resources/config/definition/service_worker.php

-
message: "#^Cannot access offset 'max_image_age' on mixed\\.$#"
count: 1
path: src/Resources/config/definition/service_worker.php

-
message: "#^Cannot access offset 'max_image_cache…' on mixed\\.$#"
count: 1
path: src/Resources/config/definition/service_worker.php

-
message: "#^Cannot access offset 'network_timeout…' on mixed\\.$#"
count: 1
path: src/Resources/config/definition/service_worker.php

-
message: "#^Cannot access offset 'offline_fallback' on mixed\\.$#"
count: 2
path: src/Resources/config/definition/service_worker.php

-
message: "#^Cannot access offset 'page_cache' on mixed\\.$#"
count: 2
path: src/Resources/config/definition/service_worker.php

-
message: "#^Cannot access offset 'page_cache_name' on mixed\\.$#"
count: 1
path: src/Resources/config/definition/service_worker.php

-
message: "#^Cannot access offset 'page_fallback' on mixed\\.$#"
count: 1
path: src/Resources/config/definition/service_worker.php

-
message: "#^Cannot access offset 'static_regex' on mixed\\.$#"
count: 1
path: src/Resources/config/definition/service_worker.php

-
message: "#^Cannot access offset 'warm_cache_urls' on mixed\\.$#"
count: 1
path: src/Resources/config/definition/service_worker.php

-
message: "#^Strict comparison using \\!\\=\\= between mixed and null will always evaluate to true\\.$#"
count: 4
path: src/Resources/config/definition/service_worker.php

-
message: "#^Call to an undefined method Symfony\\\\Component\\\\Config\\\\Definition\\\\Builder\\\\NodeParentInterface\\:\\:end\\(\\)\\.$#"
count: 1
Expand Down
17 changes: 17 additions & 0 deletions src/Dto/AssetCache.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

namespace SpomkyLabs\PwaBundle\Dto;

use Symfony\Component\Serializer\Attribute\SerializedName;

final class AssetCache
{
public bool $enabled = true;

#[SerializedName('cache_name')]
public string $cacheName = 'assets';

public string $regex = '/\.(css|js|json|xml|txt|map|ico|png|jpe?g|gif|svg|webp|bmp)$/';
}
24 changes: 24 additions & 0 deletions src/Dto/FontCache.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

declare(strict_types=1);

namespace SpomkyLabs\PwaBundle\Dto;

use Symfony\Component\Serializer\Attribute\SerializedName;

final class FontCache
{
public bool $enabled = true;

#[SerializedName('cache_name')]
public string $cacheName = 'fonts';

#[SerializedName('regex')]
public string $regex = '/\.(ttf|eot|otf|woff2)$/';

#[SerializedName('max_entries')]
public int $maxEntries = 60;

#[SerializedName('max_age')]
public int $maxAge = 60;
}
24 changes: 24 additions & 0 deletions src/Dto/ImageCache.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

declare(strict_types=1);

namespace SpomkyLabs\PwaBundle\Dto;

use Symfony\Component\Serializer\Attribute\SerializedName;

final class ImageCache
{
public bool $enabled = true;

#[SerializedName('cache_name')]
public string $cacheName = 'assets';

#[SerializedName('regex')]
public string $regex = '/\.(ico|png|jpe?g|gif|svg|webp|bmp)$/';

#[SerializedName('max_entries')]
public int $maxEntries = 60;

#[SerializedName('max_age')]
public int $maxAge = 60;
}
21 changes: 21 additions & 0 deletions src/Dto/OfflineFallback.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);

namespace SpomkyLabs\PwaBundle\Dto;

use Symfony\Component\Serializer\Attribute\SerializedName;

final class OfflineFallback
{
public bool $enabled = true;

#[SerializedName('page')]
public null|Url $pageFallback = null;

#[SerializedName('image')]
public null|Asset $imageFallback = null;

#[SerializedName('font')]
public null|Asset $fontFallback = null;
}
26 changes: 26 additions & 0 deletions src/Dto/PageCache.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

declare(strict_types=1);

namespace SpomkyLabs\PwaBundle\Dto;

use Symfony\Component\Serializer\Attribute\SerializedName;

final class PageCache
{
public bool $enabled = true;

#[SerializedName('cache_name')]
public string $cacheName = 'pages';

#[SerializedName('regex')]
public string $regex = '/\.(ico|png|jpe?g|gif|svg|webp|bmp)$/';

#[SerializedName('network_timeout')]
public int $networkTimeout = 3;

/**
* @var array<Url>
*/
public array $urls = [];
}
77 changes: 12 additions & 65 deletions src/Dto/Workbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace SpomkyLabs\PwaBundle\Dto;

use JetBrains\PhpStorm\Deprecated;
use Symfony\Component\Serializer\Attribute\SerializedName;

final class Workbox
Expand All @@ -22,76 +21,24 @@ final class Workbox
#[SerializedName('cache_manifest')]
public bool $cacheManifest;

#[SerializedName('google_fonts')]
public GoogleFontCache $googleFontCache;

#[SerializedName('workbox_import_placeholder')]
#[Deprecated('No longer used.')]
public string $workboxImportPlaceholder;

#[SerializedName('standard_rules_placeholder')]
#[Deprecated('No longer used.')]
public string $standardRulesPlaceholder;

#[SerializedName('offline_fallback_placeholder')]
#[Deprecated('No longer used.')]
public string $offlineFallbackPlaceholder;

#[SerializedName('widgets_placeholder')]
#[Deprecated('No longer used.')]
public string $widgetsPlaceholder;

#[SerializedName('page_fallback')]
public null|Url $pageFallback = null;

#[SerializedName('image_fallback')]
public null|Asset $imageFallback = null;

#[SerializedName('font_fallback')]
public null|Asset $fontFallback = null;

/**
* @var array<Url>
*/
#[SerializedName('warm_cache_urls')]
public array $warmCacheUrls = [];
#[SerializedName('image_cache')]
public ImageCache $imageCache;

#[SerializedName('network_timeout_seconds')]
public int $networkTimeoutSeconds = 3;
#[SerializedName('font_cache')]
public FontCache $fontCache;

#[SerializedName('max_font_age')]
public int $maxFontAge = 60 * 60 * 24 * 365;
#[SerializedName('page_cache')]
public PageCache $pageCache;

#[SerializedName('max_font_cache_entries')]
public int $maxFontCacheEntries = 60;
#[SerializedName('asset_cache')]
public AssetCache $assetCache;

#[SerializedName('max_image_age')]
public int $maxImageAge = 60 * 60 * 24 * 365;

#[SerializedName('max_image_cache_entries')]
public int $maxImageCacheEntries = 60;

#[SerializedName('image_regex')]
public string $imageRegex = '/\.(ico|png|jpe?g|gif|svg|webp|bmp)$/';

#[SerializedName('static_regex')]
public string $staticRegex = '/\.(css|m?jsx?|json|xml|txt|map|webmanifest)$/';
#[SerializedName('google_fonts')]
public GoogleFontCache $googleFontCache;

#[SerializedName('font_regex')]
public string $fontRegex = '/\.(ttf|eot|otf|woff2)$/';
#[SerializedName('offline_fallback')]
public OfflineFallback $offlineFallback;

#[SerializedName('clear_cache')]
public bool $clearCache = true;

#[SerializedName('image_cache_name')]
public string $imageCacheName = 'images';

#[SerializedName('font_cache_name')]
public string $fontCacheName = 'fonts';

#[SerializedName('page_cache_name')]
public string $pageCacheName = 'pages';

#[SerializedName('asset_cache_name')]
public string $assetCacheName = 'assets';
}
Loading

0 comments on commit 5ba6f35

Please sign in to comment.