---
title: "Caching — Connections for Laravel | Roundly"
description: "Permission checks are memoised per connector–connectable pair, invalidated on every package write, and bypassable with force: true."
url: https://roundly-consulting.com/open-source/docs/connections-for-laravel/caching
language: en
---

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

[Connections for Laravel](https://roundly-consulting.com/open-source/docs/connections-for-laravel.md)

# Caching

hasPermissionThroughConnection() — and everything built on it: the any/all variants, permissions()->has() / hasAny() / hasAll() and the Gate hook — memoises the resolved connection per connector–connectable pair, so a page that checks access many times queries once:

```php
$user->hasPermissionThroughConnection($team, 'edit');               // queries once, then memoised
$user->hasPermissionThroughConnection($team, 'view');               // served from the cache
$user->hasPermissionThroughConnection($team, 'edit', force: true);  // re-query and refresh the entry

Connections::between($user, $team)->permissions()->revoke('edit');  // writes invalidate the pair
$user->hasPermissionThroughConnection($team, 'edit');               // false — no force needed
```

- The cache stores the Connection row, not the answer, so status and expiry are evaluated at check time.
- Every write through the package — facade, trait, actions, bulk verbs and sync — invalidates the affected pair; connections:prune and Connections::prune() drop the whole cache once they remove rows.
- isConnectedTo() and the other connected-to checks always query the database.
- Set cache.enabled to false to re-query on every check.

## Cache lifetime

The cache is a scoped container instance, dropped at the start of every request and queued job — Octane and queue:work included — so a cached permission never outlives one. Within a single request or job it can still miss changes made outside the package’s write path, such as another process or a direct Eloquent update to a Connection. Pass force: true where freshness matters, disable the cache, or flush it mid-request through the facade:

```php
use RoundlyConsulting\Connections\Facades\Connections;

Connections::flushCache();   // forget every memoised connection
```

## 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/connections-for-laravel.md)
