No results
1
Caching
Lenny P. edited this page 2026-10-07 08:36:40 +02:00
Table of contents
Caching
Enable caching
Use the WithCache trait:
use RealZone22\PenguTables\Traits\WithCache;
class Users extends PenguTable
{
use WithCache;
protected function setupOptions(): Options
{
return parent::setupOptions()
->withCache(
enabled: true,
duration: 300,
keyPrefix: 'users_table',
);
}
}
The cache key contains the current pagination page, page size, search term, sort state, and active filters.
Cache configuration
->withCache(
enabled: true,
duration: 600,
keyPrefix: 'users',
)
enabledenables or disables table data caching.durationis the cache lifetime in seconds.keyPrefixmakes the cache namespace explicit.
If no prefix is provided, the package generates one from the table class name.
Clear cache
Clear the current table cache entry:
$this->clearCurrentCache();
Refresh the current state:
$this->refreshCache();
Clear all cache entries for the table:
$this->clearTableCache();
clearTableCache() uses cache tags. Use a cache driver that supports tags
when relying on this method.
When to clear cache
Clear or refresh the cache after mutations that affect table rows:
public function saveUser(): void
{
// Persist the changes...
$this->refreshCache();
}