Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
f31d5e5
chore: update dependencies and workflows to support PHP 8.3+ and Lara…
mostafaznv Dec 12, 2025
1d493ae
docs: update compatibility table for LaraCache versions and links
mostafaznv Dec 12, 2025
345ad4a
docs: typo
mostafaznv Dec 12, 2025
447e1f2
docs: improve config file comments for clarity and consistency
mostafaznv Dec 12, 2025
690c7fc
refactor: replace custom `CacheEnum` implementation with native `PHP`…
mostafaznv Dec 12, 2025
00fd5ed
docs: enhance function docblocks for clarity and consistency
mostafaznv Dec 12, 2025
cceeaeb
docs: add type-hinted docblocks to observer methods for consistency w…
mostafaznv Dec 12, 2025
0115581
refactor: adjust method signatures and reposition abstract method for…
mostafaznv Dec 12, 2025
5942f45
refactor: simplify conditional logic and improve readability in cache…
mostafaznv Dec 12, 2025
c3e62b5
refactor: streamline `CacheEntity` by removing redundant docblocks, s…
mostafaznv Dec 12, 2025
5382d8a
refactor: remove unnecessary blank line in `LaraCacheServiceProvider`
mostafaznv Dec 12, 2025
11064bd
refactor: update method signatures to use string instead of mixed types
mostafaznv Dec 13, 2025
4c604ec
refactor: remove unnecessary blank lines and adjust spacing for consi…
mostafaznv Dec 13, 2025
e5c30e7
refactor: make `$model` property readonly, adjust constants, and stre…
mostafaznv Dec 13, 2025
720b700
refactor: update method signatures in `LaraCache` and facade to use s…
mostafaznv Dec 13, 2025
2b7cf66
refactor: improve exception messages for clarity and consistency
mostafaznv Dec 13, 2025
5a19462
refactor: tighten ttl check in `CacheData` to prevent negative values
mostafaznv Dec 13, 2025
5e83c48
refactor: clean up imports and adjust docblock for `LaraCache` type u…
mostafaznv Dec 13, 2025
b5091c4
refactor: adjust command signature spacing for consistency across all…
mostafaznv Dec 13, 2025
86b2900
refactor: add `ModelOptionIsRequired` exception and update `CommandDa…
mostafaznv Dec 13, 2025
35bd2d4
refactor: clean up imports and simplify `LaraCache` type usage across…
mostafaznv Dec 13, 2025
22a1fef
fix: respect creation rules for queueable cache entities
mostafaznv Dec 14, 2025
fd342aa
fix: ensure debounce logic respects entity callability during cache i…
mostafaznv Dec 15, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 2 additions & 25 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,13 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest]
php: [8.0, 8.1, 8.2, 8.3, 8.4, 8.5]
laravel: ['8.*', '9.*', '10.*', '11.*', '12.*']
php: [8.3, 8.4, 8.5]
laravel: ['12.*']
coverage: [none]
dependency-version: [prefer-stable]
include:
- laravel: 10.*
testbench: 8.*
- laravel: 9.*
testbench: 7.*
- laravel: 8.*
testbench: 6.*
- laravel: 11.*
testbench: 9.*
- laravel: 12.*
testbench: 10.*
exclude:
- laravel: 10.*
php: 8.0
- laravel: 11.*
php: 8.0
- laravel: 11.*
php: 8.1
- laravel: 12.*
php: 8.0
- laravel: 12.*
php: 8.1

name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.os }} - ${{ matrix.dependency-version }}

Expand Down Expand Up @@ -65,11 +46,7 @@ jobs:

- name: Install dependencies
run: |
if [ "${{ matrix.laravel }}" = "11.*" ] && [ "${{ matrix.php }}" = "8.5" ]; then
composer require "phpunit/phpunit:^12" "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update
fi
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update

composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction --no-suggest

- name: Execute tests
Expand Down
1 change: 1 addition & 0 deletions .phpunit.cache/test-results

Large diffs are not rendered by default.

11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,17 @@ Therefore, if you decide to use my packages, please kindly consider making a don

## Requirements:

- PHP 8.0.2 or higher
- Laravel 8.40.0 or higher
- PHP 8.3 or higher
- Laravel 12 or higher


To install LaraCache on older Laravel/PHP versions, consult the compatibility table below to determine which LaraCache release to use:

| Laravel Version | PHP Version | LaraCache Version |
|-----------------|---------------|-------------------------------------------------------------|
| 8.40.0 — 12.x | 8.0.2 — 8.5 | [2.5.2](https://github.com/mostafaznv/laracache/tree/2.5.2) |
| 12.x | 8.3 or higher | master (3.x) |

## Installation

1. ##### Install the package via composer:
Expand Down
11 changes: 5 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,13 @@
"minimum-stability": "dev",
"prefer-stable": true,
"require": {
"php": "^8.0.2",
"laravel/framework": "^8.40.0|^9.0|^10.0|^11.0|^12.0"
"php": "^8.3",
"laravel/framework": "^12.0"
},
"require-dev": {
"phpunit/phpunit": "^9.5.10|^10.0|^11.5.3|^12.4.4",
"orchestra/testbench": "^6.0|^7.0|^8.0|^9.0|^10.0",
"pestphp/pest": "^1.20|^2.34|^3.7|^4.1",
"spatie/pest-plugin-test-time": "^1.0|^2.1"
"orchestra/testbench": "^10.0",
"pestphp/pest": "^3.7|^4.1",
"spatie/pest-plugin-test-time": "^2.1"
},
"autoload": {
"psr-4": {
Expand Down
31 changes: 17 additions & 14 deletions config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@
| Cache Driver
|--------------------------------------------------------------------------
|
| The default mechanism for handling cache storage.
|
| If you keep this option null, LaraCache will use the default cache
| storage from config/cache.php
| Defines the cache driver to be used by LaraCache.
| If set to null, LaraCache will fall back to the application's default
| cache store configured in `config/cache.php`.
|
*/

Expand All @@ -20,8 +19,9 @@
| Cache List Key
|--------------------------------------------------------------------------
|
| LaraCache uses a separate list to store name of all entities. using these
| keys, we can perform some actions to all entities (such as update or delete them)
| Key used by LaraCache to maintain a registry of entity names. This list
| enables operations across all registered entities (for example, bulk
| updates or deletions).
|
*/

Expand All @@ -32,8 +32,8 @@
| First Day of Week
|--------------------------------------------------------------------------
|
| In some regions, saturday is first day of the week and in another regions
| it may be different
| Specifies the first day of the week. This value may vary by region.
| Uses a Carbon constant for clarity and consistency.
|
*/

Expand All @@ -44,8 +44,8 @@
| Last Day of Week
|--------------------------------------------------------------------------
|
| In some regions, friday is last day of the week and in another regions
| it may be different
| Specifies the last day of the week. Adjust this value to match your
| regional or business conventions.
|
*/

Expand All @@ -56,7 +56,8 @@
| Queue
|--------------------------------------------------------------------------
|
| Sometimes caching process is very heavy, so you have to queue the process and do it in background.
| Configuration for background processing. Use queues to offload heavy or
| long-running cache operations. Set `status` to true to enable queuing.
|
*/

Expand All @@ -71,7 +72,9 @@
| Debounce
|--------------------------------------------------------------------------
|
| If you want to debounce the cache refresh process, you can enable this option.
| Debounce settings control deferred refresh behavior to prevent frequent
| or redundant cache refreshes. `wait` is specified in seconds. Debounce
| can be processed via a dedicated queue configuration below.
|
*/

Expand All @@ -90,9 +93,9 @@
| Groups
|--------------------------------------------------------------------------
|
| You can group some entities and perform some actions on them.
| Define logical groups of entities to perform collective operations.
| Example structure:
|
| Example:
| 'groups' => [
| 'group-1' => [
| [
Expand Down
6 changes: 4 additions & 2 deletions src/Actions/DeleteCacheAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

use Mostafaznv\LaraCache\Actions\Support\UpdateDeleteCache;
use Mostafaznv\LaraCache\DTOs\CommandData;
use Mostafaznv\LaraCache\Traits\LaraCache;


class DeleteCacheAction extends UpdateDeleteCache
{
Expand All @@ -24,7 +26,7 @@ public function run(CommandData $data): void
}

/**
* @param \Mostafaznv\LaraCache\Traits\LaraCache $model
* @param LaraCache $model
* @return void
*/
private function deleteAll(string $model): void
Expand All @@ -39,7 +41,7 @@ private function deleteAll(string $model): void
}

/**
* @param \Mostafaznv\LaraCache\Traits\LaraCache $model
* @param LaraCache $model
* @param array $entities
* @return void
*/
Expand Down
1 change: 1 addition & 0 deletions src/Actions/DeleteGroupCacheAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Mostafaznv\LaraCache\Actions\Support\UpdateDeleteCache;


class DeleteGroupCacheAction extends UpdateDeleteCache
{
public function run(string $group): void
Expand Down
1 change: 1 addition & 0 deletions src/Actions/Support/UpdateDeleteCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Mostafaznv\LaraCache\Exceptions\CacheGroupNotExist;
use Mostafaznv\LaraCache\Exceptions\CacheGroupValueIsNotValid;


abstract class UpdateDeleteCache
{
public function __construct(protected ?Command $console) {}
Expand Down
6 changes: 4 additions & 2 deletions src/Actions/UpdateCacheAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

use Mostafaznv\LaraCache\Actions\Support\UpdateDeleteCache;
use Mostafaznv\LaraCache\DTOs\CommandData;
use Mostafaznv\LaraCache\Traits\LaraCache;


class UpdateCacheAction extends UpdateDeleteCache
{
Expand All @@ -24,7 +26,7 @@ public function run(CommandData $data): void
}

/**
* @param \Mostafaznv\LaraCache\Traits\LaraCache $model
* @param LaraCache $model
* @return void
*/
private function updateAll(string $model): void
Expand All @@ -39,7 +41,7 @@ private function updateAll(string $model): void
}

/**
* @param \Mostafaznv\LaraCache\Traits\LaraCache $model
* @param LaraCache $model
* @param array $entities
* @return void
*/
Expand Down
1 change: 1 addition & 0 deletions src/Actions/UpdateGroupCacheAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Mostafaznv\LaraCache\Actions\Support\UpdateDeleteCache;


class UpdateGroupCacheAction extends UpdateDeleteCache
{
public function run(string $group): void
Expand Down
39 changes: 21 additions & 18 deletions src/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@
namespace Mostafaznv\LaraCache;

use Mostafaznv\LaraCache\DTOs\CacheData;
use Mostafaznv\LaraCache\DTOs\CacheEvent;
use Mostafaznv\LaraCache\Enums\CacheEvent;
use Mostafaznv\LaraCache\Jobs\RefreshCache;
use Mostafaznv\LaraCache\Traits\InteractsWithCache;
use Mostafaznv\LaraCache\Utils\RefreshDebouncer;


class Cache
{
use InteractsWithCache;


public function get(string $name, bool $withCacheData = false): mixed
{
$cache = $this->retrieve($name);
Expand All @@ -35,10 +37,7 @@ public function updateAll(): void
$this->updateLaraCacheModelsList();

foreach ($this->model::cacheEntities() as $entity) {
$this->updateCacheEntity(
name: $entity->name,
entity: $entity
);
$this->updateCacheEntity($entity->name, entity: $entity);
}
}

Expand All @@ -61,22 +60,26 @@ public function refresh(CacheEvent $event): void

foreach ($this->model::cacheEntities() as $entity) {
if ($entity->debounce) {
$this->initCache($entity, $entity->getTtl());

RefreshDebouncer::dispatch(
model: $this->model,
name: $entity->name,
queueConnection: $entity->queueConnection,
queueName: $entity->queueName,
wait: $entity->debounceWaitTime
);
if ($this->entityIsCallable($entity, $event)) {
$this->initCache($entity, $entity->getTtl());

RefreshDebouncer::dispatch(
model: $this->model,
name: $entity->name,
queueConnection: $entity->queueConnection,
queueName: $entity->queueName,
wait: $entity->debounceWaitTime
);
}
}
else if ($entity->isQueueable) {
$this->initCache($entity, $entity->getTtl());
if ($this->entityIsCallable($entity, $event)) {
$this->initCache($entity, $entity->getTtl());

RefreshCache::dispatch($this->model, $entity->name, $event)
->onConnection($entity->queueConnection)
->onQueue($entity->queueName);
RefreshCache::dispatch($this->model, $entity->name)
->onConnection($entity->queueConnection)
->onQueue($entity->queueName);
}
}
else {
$this->updateCacheEntity($entity->name, $event, $entity);
Expand Down
Loading