---
title: "Caching and eager loading — Opening Hours for Laravel | Roundly"
description: "Revision-keyed definition caching with nothing to invalidate, a per-request memo, and list pages without N+1 queries."
url: https://roundly-consulting.com/open-source/docs/opening-hours-for-laravel/caching
language: en
---

[All packages](https://roundly-consulting.com/open-source.md)

[Opening Hours for Laravel](https://roundly-consulting.com/open-source/docs/opening-hours-for-laravel.md)

# Caching and eager loading

Compiled definitions are cached per (calendar, revision). Every write bumps the revision inside its transaction, so there is nothing to invalidate — old keys simply expire by cache.ttl. The cache stores plain arrays, uses no tags and works with any store.

## List pages without N+1

```php
Clinic::query()->withOpeningHours()->paginate();                  // headers only (cache on)
Clinic::query()->withOpeningHours(definitions: true)->paginate(); // full definitions (cache off)
```

With the cache on, headers are enough — the revision lives on the header. Hosts without a cache load full definitions with definitions: true.

## Staying fresh

Direct Eloquent edits of schedules, exceptions and ranges bump the revision automatically. After raw SQL edits, or when what openingHoursTimezone() returns changes, call refresh():

```php
use RoundlyConsulting\OpeningHours\Facades\OpeningHours;

OpeningHours::refresh($clinic);            // after raw SQL or a changed openingHoursTimezone()
OpeningHours::refresh($clinic, 'pickup');  // a named calendar
OpeningHours::flushMemo();                 // clear the per-request memo
```

The manager behind the facade is bound scoped, so its memo of compiled definitions lives for one request or job — safe under Octane and queues. The owner’s timezone hook and dynamic providers are resolved per call, never cached. A corrupt cache payload is treated as a miss and recompiled. A definition read inside an open database transaction is neither cached nor memoised — a rollback would hand its revision out again.

## Show your open-source love

This package is free and MIT-licensed. If it saves you time, a one-off donation or a Patreon membership keeps it maintained, tested and documented.

[More ways to support, including crypto](https://roundly-consulting.com/support-us.md)

By donating, you agree to our [donation terms](https://roundly-consulting.com/donation-terms.md).

[Support our open source work (opens in a new tab)](https://donate.stripe.com/dRmeVe8FX5PF1Qd9pXcEw00) [Join us on Patreon (opens in a new tab)](https://www.patreon.com/cw/roundly)

## Want this built into your product?

We integrate our packages into custom Laravel and AI builds. Tell us what you're working on and we'll reply within 48 hours.

[Get a quote in 48 hours](https://roundly-consulting.com/contact.md) [Browse all packages](https://roundly-consulting.com/open-source/docs/opening-hours-for-laravel.md)
