### Install laravel-image-cache via Composer Source: https://github.com/jeffersongoncalves/laravel-image-cache/blob/main/README.md Installs the package via Composer. ```bash composer require jeffersongoncalves/laravel-image-cache ``` -------------------------------- ### Read cached image with get() Source: https://github.com/jeffersongoncalves/laravel-image-cache/blob/main/README.md Reads back a cached image, returning an array with body and type, or null if never warmed successfully. ```php $image = $cache->get('project-42'); // ['body' => '', 'type' => 'image/png'] or null if never warmed successfully ``` -------------------------------- ### Instantiate ImageCache and warm cache Source: https://github.com/jeffersongoncalves/laravel-image-cache/blob/main/README.md Constructs an ImageCache instance with a public disk, 'og-images' path prefix, and a TTL of 86400 seconds. Then warms the cache for key 'project-42' with an untrusted image URL. The package does not decide which URL to fetch or which hosts are allowed; it only guards where the URL resolves to via the SSRF guard. ```php $cache = new ImageCache(disk: 'public', pathPrefix: 'og-images', ttlSeconds: 86400); $cache->warm('project-42', $untrustedImageUrl); ``` -------------------------------- ### Publish image-cache-config Source: https://github.com/jeffersongoncalves/laravel-image-cache/blob/main/README.md Publishes the package's configuration file. ```bash php artisan vendor:publish --tag="image-cache-config" ``` -------------------------------- ### Construct ImageCache with disk, prefix, and TTL Source: https://github.com/jeffersongoncalves/laravel-image-cache/blob/main/README.md Constructs an ImageCache instance with the Laravel disk, path prefix, and TTL (defaults to 24 hours). ```php use JeffersonGoncalves\ImageCache\ImageCache; $cache = new ImageCache(disk: 'public', pathPrefix: 'og-images', ttlSeconds: 86400); ``` -------------------------------- ### Warm cache with warm() Source: https://github.com/jeffersongoncalves/laravel-image-cache/blob/main/README.md Warms the cache by fetching and persisting the image if the disk copy is missing or older than the TTL. No-ops (returns true) when fresh, never throws, and returns false on any failure while leaving stale copies untouched. ```php $cache->warm(key: 'project-42', url: $project->social_image); ``` -------------------------------- ### Serve cached image from controller with response() Source: https://github.com/jeffersongoncalves/laravel-image-cache/blob/main/README.md Controller method using response() to return a ready-to-send response with Content-Type and X-Content-Type-Options: nosniff, or null when the key was never warmed. ```php public function show(string $slug) { return $cache->response($slug) ?? abort(404); } ``` -------------------------------- ### Run tests with composer test Source: https://github.com/jeffersongoncalves/laravel-image-cache/blob/main/README.md Runs the test suite for the package. Use this command to execute all tests defined in the project. ```bash composer test ``` -------------------------------- ### Warm with pre-resolved SsrfGuard entries Source: https://github.com/jeffersongoncalves/laravel-image-cache/blob/main/README.md Passes pre-resolved CURLOPT_RESOLVE entries to warm() to avoid a second DNS lookup when you already validated the URL yourself. Passing an empty array skips pinning entirely for trusted URLs. ```php use JeffersonGoncalves\SsrfGuard\SsrfGuard; $resolve = app(SsrfGuard::class)->resolveEntries($url); if ($resolve !== null) { $cache->warm('project-42', $url, $resolve); } ``` -------------------------------- ### Published image-cache config file Source: https://github.com/jeffersongoncalves/laravel-image-cache/blob/main/README.md Published config file with timeout and max_redirects settings, both configurable via environment variables with defaults of 8 and 3 respectively. ```php return [ 'timeout' => (int) env('IMAGE_CACHE_TIMEOUT', 8), 'max_redirects' => (int) env('IMAGE_CACHE_MAX_REDIRECTS', 3), ]; ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.