Add cache
This commit is contained in:
parent
ed17bd1945
commit
3f91586b62
|
@ -100,7 +100,8 @@ class Plugin extends PluginBase
|
||||||
return [
|
return [
|
||||||
'filters' => [
|
'filters' => [
|
||||||
'resize' => function($media, $size = 'original') {
|
'resize' => function($media, $size = 'original') {
|
||||||
return Cache::rememberForever("resize.{$size}.{$media}", fn () => app(TagGenerator::class)->generate($media, $size));
|
$normalPath = app(FileObserver::class)->normalizePath($media);
|
||||||
|
return Cache::rememberForever("resize.{$size}.{$normalPath}", fn () => app(TagGenerator::class)->generate($media, $size));
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
|
|
|
@ -106,18 +106,24 @@ class ImageTagTest extends TestCase
|
||||||
Setting::set('breakpoints', [640]);
|
Setting::set('breakpoints', [640]);
|
||||||
$this->media->put('/pages/test.svg', file_get_contents(__DIR__.'/stub/close.svg'));
|
$this->media->put('/pages/test.svg', file_get_contents(__DIR__.'/stub/close.svg'));
|
||||||
|
|
||||||
$this->assertFalse(str_contains(
|
$output = app(Twig::class)->parse('{{"pages/test.svg" | resize}}');
|
||||||
app(Twig::class)->parse('{{"pages/test.svg" | resize}}'),
|
|
||||||
'srcset',
|
$this->assertFalse(str_contains($output, 'srcset'));
|
||||||
));
|
$this->assertFalse(str_contains($output, 'sizes'));
|
||||||
$this->assertFalse(str_contains(
|
$this->assertTrue(str_contains($output, 'src="'.$this->media->findFiles('/pages/test.svg')[0]->publicUrl.'"'));
|
||||||
app(Twig::class)->parse('{{"pages/test.svg" | resize}}'),
|
$this->assertEquals($output, Cache::get('resize.original.pages/test.svg'));
|
||||||
'sizes',
|
}
|
||||||
));
|
|
||||||
$this->assertTrue(str_contains(
|
public function testNormalizeFilePathForCache()
|
||||||
app(Twig::class)->parse('{{"pages/test.svg" | resize}}'),
|
{
|
||||||
'src="'.$this->media->findFiles('/pages/test.svg')[0]->publicUrl.'"',
|
Setting::set('folders', ['pages']);
|
||||||
));
|
Setting::set('sizes', [['name' => 'size', 'aspect_ratio' => '1200x280']]);
|
||||||
|
Setting::set('breakpoints', [640]);
|
||||||
|
$this->media->put('/pages/test.svg', file_get_contents(__DIR__.'/stub/close.svg'));
|
||||||
|
|
||||||
|
$output = app(Twig::class)->parse('{{"/pages/test.svg" | resize}}');
|
||||||
|
|
||||||
|
$this->assertEquals($output, Cache::get('resize.original.pages/test.svg'));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue