Generate cache

This commit is contained in:
Philipp Lang 2021-09-06 13:34:10 +02:00
parent 341349848d
commit 73e6e15e24
2 changed files with 15 additions and 1 deletions

View File

@ -100,7 +100,7 @@ class Plugin extends PluginBase
return [ return [
'filters' => [ 'filters' => [
'resize' => function($media, $size = 'original') { 'resize' => function($media, $size = 'original') {
return app(TagGenerator::class)->generate($media, $size); return Cache::rememberForever("resize.{$size}.{$media}", fn () => app(TagGenerator::class)->generate($media, $size));
}, },
] ]
]; ];

View File

@ -5,8 +5,10 @@ namespace Aweos\Resizer\Tests\MediaTest;
use Aweos\Resizer\Classes\TagGenerator; use Aweos\Resizer\Classes\TagGenerator;
use Aweos\Resizer\Models\Setting; use Aweos\Resizer\Models\Setting;
use Aweos\Resizer\Tests\TestCase; use Aweos\Resizer\Tests\TestCase;
use Cache;
use Event; use Event;
use Illuminate\Http\UploadedFile; use Illuminate\Http\UploadedFile;
use October\Rain\Parse\Twig;
use Storage; use Storage;
class ImageTagTest extends TestCase class ImageTagTest extends TestCase
@ -85,6 +87,18 @@ class ImageTagTest extends TestCase
)); ));
} }
public function testGenerateCache()
{
Setting::set('folders', ['pages']);
Setting::set('sizes', [['name' => 'size', 'aspect_ratio' => '1200x280']]);
Setting::set('breakpoints', [640]);
$this->media->put('/pages/test.jpg', UploadedFile::fake()->image('test.jpg', 1920, 899)->get());
UploadedFile::fake()->image('test.jpg', 640, 149)->storeAs('uploads/public/c/pages', 'test-640x149.jpg', 'local');
$output = app(Twig::class)->parse('{{"pages/test.jpg" | resize}}');
$this->assertEquals($output, Cache::get('resize.original.pages/test.jpg'));
}
public function testPickOriginalImageWhenSvgIsGiven() public function testPickOriginalImageWhenSvgIsGiven()
{ {
Setting::set('folders', ['pages']); Setting::set('folders', ['pages']);