8000 Add config option to ignore view cache timestamps by pizkaz · Pull Request #55536 · laravel/framework · GitHub
[go: up one dir, main page]

Skip to content

Add config option to ignore view cache timestamps #55536

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 24, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add config option to ignore view cache timestamps
  • Loading branch information
pizkaz committed Apr 24, 2025
commit 191271aa170919aa320fce14376055601d32276a
17 changes: 17 additions & 0 deletions config/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,21 @@
realpath(storage_path('framework/views'))
),

/*
|--------------------------------------------------------------------------
| Ignore view cache timestamps
|--------------------------------------------------------------------------
|
| This option determines whether timestamps of cached views should be
| ignored. You should only enable this if you have pre-compiled all views
| with `artisan view:cache`. Whenever a view templates changes, you must
| run this command again to update the view cache.
|
*/

'ignore_cache_timestamps' => env(
'VIEW_CACHE_IGNORE_TIMESTAMPS',
false
),

];
15 changes: 14 additions & 1 deletion src/Illuminate/View/Compilers/Compiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,14 @@ abstract class Compiler
*
* @var string
*/
protected $compiledExtension = 'php';
protected $compiledExtension;

/**
* Determines if view cache timestamps should be ignored.
*
* @var bool
*/
protected $ignoreCacheTimestamps;

/**
* Create a new compiler instance.
Expand All @@ -61,6 +68,7 @@ public function __construct(
$basePath = '',
$shouldCache = true,
$compiledExtension = 'php',
$ignoreCacheTimestamps = false,
) {
if (! $cachePath) {
throw new InvalidArgumentException('Please provide a valid cache path.');
Expand All @@ -71,6 +79,7 @@ public function __construct(
$this->basePath = $basePath;
$this->shouldCache = $shouldCache;
$this->compiledExtension = $compiledExtension;
$this->ignoreCacheTimestamps = $ignoreCacheTimestamps;
}

/**
Expand All @@ -94,6 +103,10 @@ public function getCompiledPath($path)
*/
public function isExpired($path)
{
if ($this->ignoreCacheTimestamps) {
return false;
}

if (! $this->shouldCache) {
return true;
}
Expand Down
1 change: 1 addition & 0 deletions src/Illuminate/View/ViewServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ public function registerBladeCompiler()
$app['config']->get('view.relative_hash', false) ? $app->basePath() : '',
$app['config']->get('view.cache', true),
$app['config']->get('view.compiled_extension', 'php'),
$app['config']->get('view.ignore_cache_timestamps', false),
), function ($blade) {
$blade->component('dynamic-component', DynamicComponent::class);
});
Expand Down
6 changes: 6 additions & 0 deletions tests/View/ViewBladeCompilerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ public function testIsExpiredReturnsTrueWhenUseCacheIsFalse()
$this->assertTrue($compiler->isExpired('foo'));
}

public function testIsExpiredReturnsFalseWhenIgnoreCacheTimestampsIsTrue()
{
$compiler = new BladeCompiler($this->getFiles(), __DIR__, ignoreCacheTimestamps: true);
$this->assertFalse($compiler->isExpired('foo'));
}

public function testCompilePathIsProperlyCreated()
{
$compiler = new BladeCompiler($this->getFiles(), __DIR__);
Expand Down
0