Caching and storage | laravel-og-image-go | Spatie       

 SPATIE  

laravel-og-image-go
===================

spatie.be/open-source

  [Docs](https://spatie.be/docs)  [Laravel-og-image-go](https://spatie.be/docs/laravel-og-image-go/v1)  Basic-usage  Caching and storage

 Version   v1      

 Other versions for crawler [v1](https://spatie.be/docs/laravel-og-image-go/v1) 

  Caching and storage    
- [ Introduction ](https://spatie.be/docs/laravel-og-image-go/v1/introduction)
- [ Requirements ](https://spatie.be/docs/laravel-og-image-go/v1/requirements)
- [ Installation &amp; setup ](https://spatie.be/docs/laravel-og-image-go/v1/installation-setup)
- [ Questions and issues ](https://spatie.be/docs/laravel-og-image-go/v1/questions-issues)
- [ Testing ](https://spatie.be/docs/laravel-og-image-go/v1/testing)
- [ Releasing ](https://spatie.be/docs/laravel-og-image-go/v1/releasing)
- [ Changelog ](https://spatie.be/docs/laravel-og-image-go/v1/changelog)
- [ Support us ](https://spatie.be/docs/laravel-og-image-go/v1/support-us)
- [ About us ](https://spatie.be/docs/laravel-og-image-go/v1/about-us)

Basic usage
-----------

- [ How it works ](https://spatie.be/docs/laravel-og-image-go/v1/basic-usage/how-it-works)
- [ Getting started ](https://spatie.be/docs/laravel-og-image-go/v1/basic-usage/getting-started)
- [ Customizing screenshots ](https://spatie.be/docs/laravel-og-image-go/v1/basic-usage/customizing-screenshots)
- [ Defining fallback images ](https://spatie.be/docs/laravel-og-image-go/v1/basic-usage/defining-fallback-images)
- [ Caching and storage ](https://spatie.be/docs/laravel-og-image-go/v1/basic-usage/managing-caching-and-storage)
- [ Pre-generating images ](https://spatie.be/docs/laravel-og-image-go/v1/basic-usage/pre-generating-images)
- [ Clearing generated images ](https://spatie.be/docs/laravel-og-image-go/v1/basic-usage/clearing-generated-images)

Advanced usage
--------------

- [ Customizing the page URL ](https://spatie.be/docs/laravel-og-image-go/v1/advanced-usage/customizing-the-page-url)
- [ Using a custom screenshot driver ](https://spatie.be/docs/laravel-og-image-go/v1/advanced-usage/using-a-custom-screenshot-driver)
- [ Customizing the screenshot layout ](https://spatie.be/docs/laravel-og-image-go/v1/advanced-usage/customizing-the-screenshot-layout)
- [ Customizing actions ](https://spatie.be/docs/laravel-og-image-go/v1/advanced-usage/customizing-actions)
- [ Troubleshooting ](https://spatie.be/docs/laravel-og-image-go/v1/advanced-usage/troubleshooting)
- [ Using a hosted solution ](https://spatie.be/docs/laravel-og-image-go/v1/advanced-usage/using-a-hosted-solution)
- [ Using Laravel Boost ](https://spatie.be/docs/laravel-og-image-go/v1/advanced-usage/using-laravel-boost)

 Caching and storage
===================

###  On this page 

1. [ Content-hashed URLs ](#content-content-hashed-urls)
2. [ Configuring the disk ](#content-configuring-the-disk)
3. [ Serving with Cloudflare ](#content-serving-with-cloudflare)
4. [ Serving without a CDN ](#content-serving-without-a-cdn)
5. [ Serving with S3 or other remote disks ](#content-serving-with-s3-or-other-remote-disks)
6. [ Metadata and locks ](#content-metadata-and-locks)

Content-hashed URLs
-----------------------------------------------------------------------------------------------------------------

Image URLs use an MD5 hash of the exact rendered template HTML. Explicit dimensions are included when present. Changing the HTML produces a new image URL. Old images remain until you [clear them](clearing-generated-images).

The hash matches the PHP package. It is not a signature or an authorization token. Changes to global dimensions, quality, CSS, fonts or screenshot callbacks do not change the hash. Clear generated files after changing those settings.

Configuring the disk
--------------------------------------------------------------------------------------------------------------------

Images use the `public` disk and `og-images` directory by default. Set `Config.Disk` and `Config.Path` to change them.

Serving with Cloudflare
-----------------------------------------------------------------------------------------------------------------------------

If your site is behind Cloudflare, image responses include `Cache-Control: public, max-age=86400` by default. Cloudflare can cache the image response or remote-disk redirect. Change `Config.MaxAge`, or set it to zero to send `no-store`.

Serving without a CDN
-----------------------------------------------------------------------------------------------------------------------

The application serves local files directly with Laravel's file response. You can configure your reverse proxy to serve existing files from the public disk and forward missing files to the application. Keep that rule restricted to generated image filenames, not arbitrary storage paths.

Serving with S3 or other remote disks
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------

S3 and Laravel Cloud disks return a 301 redirect to the disk's public URL rather than streaming the image through the application. Make generated objects publicly readable through your bucket policy or CDN. The package does not change object permissions. For a custom remote disk, set `Config.RemoteDisk = true`.

Metadata and locks
--------------------------------------------------------------------------------------------------------------

Use a persistent shared Laravel cache in production. Metadata maps hashes to page URLs and explicit dimensions. The first page URL for identical content wins, matching PHP behavior. Default URL resolution strips the query string.

Laravel Go's cache API requires a positive lifetime, unlike PHP's forever cache. `MetadataTTL` defaults to 30 days. Existing image files remain usable after metadata expires, but missing files require a fresh page visit before regeneration. Increase the lifetime for infrequently visited pages.

Locks are held for `LockTimeout`, defaulting to 60 seconds. Configure it longer than your maximum screenshot duration. A timeout or browser failure returns an error and leaves no stored image. Failed attempts release the lock for a later retry.

 A good
match?
-------------

### What we do best

- All things Laravel
- Custom frontend components
- Building APIs
- AI-powered features
- Simplifying things
- Clean solutions
- Integrating services

### Not our cup of tea

- WordPress themes
- Cutting corners
- Free mockups to win a job
- "Just execute the briefing"

 In short: we'd like to be a **substantial part** of your project.

 [ Get in touch via email ](mailto:info@spatie.be?subject=A%20good%20match%21&body=Tell%20us%20as%20much%20as%20you%20can%20about%0A-%20your%20online%20project%0A-%20your%20planning%0A-%20your%20budget%0A-%20%E2%80%A6%0A%0AAnything%20that%20helps%20us%20to%20start%20straightforward%21)
