Skip to content

Commit 18e3de6

Browse files
committed
Create package
0 parents  commit 18e3de6

33 files changed

+1289
-0
lines changed

.editorconfig

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
end_of_line = lf
6+
indent_size = 4
7+
indent_style = space
8+
insert_final_newline = true
9+
trim_trailing_whitespace = true
10+
11+
[*.md]
12+
trim_trailing_whitespace = false
13+
14+
[*.{yml,yaml}]
15+
indent_size = 2

.gitattributes

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Path-based git attributes
2+
# https://www.kernel.org/pub/software/scm/git/docs/gitattributes.html
3+
4+
# Ignore all test and documentation with "export-ignore".
5+
/.github export-ignore
6+
/.gitattributes export-ignore
7+
/.gitignore export-ignore
8+
/phpunit.xml.dist export-ignore
9+
/art export-ignore
10+
/docs export-ignore
11+
/tests export-ignore
12+
/workbench export-ignore
13+
/.editorconfig export-ignore
14+
/.php_cs.dist.php export-ignore
15+
/psalm.xml export-ignore
16+
/psalm.xml.dist export-ignore
17+
/testbench.yaml export-ignore
18+
/UPGRADING.md export-ignore
19+
/phpstan.neon.dist export-ignore
20+
/phpstan-baseline.neon export-ignore

.github/workflows/phpstan.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: PHPStan
2+
3+
on:
4+
push:
5+
paths:
6+
- '**.php'
7+
- 'phpstan.neon.dist'
8+
- '.github/workflows/phpstan.yml'
9+
10+
jobs:
11+
phpstan:
12+
name: phpstan
13+
runs-on: ubuntu-latest
14+
timeout-minutes: 5
15+
steps:
16+
- uses: actions/checkout@v4
17+
18+
- name: Setup PHP
19+
uses: shivammathur/setup-php@v2
20+
with:
21+
php-version: '8.4'
22+
coverage: none
23+
24+
- name: Install composer dependencies
25+
uses: ramsey/composer-install@v3
26+
27+
- name: Run PHPStan
28+
run: ./vendor/bin/phpstan --error-format=github

.github/workflows/pint.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Pint
2+
3+
on:
4+
push:
5+
paths:
6+
- '**.php'
7+
8+
permissions:
9+
contents: write
10+
11+
jobs:
12+
php-code-styling:
13+
runs-on: ubuntu-latest
14+
timeout-minutes: 5
15+
16+
steps:
17+
- name: Checkout code
18+
uses: actions/checkout@v4
19+
with:
20+
ref: ${{ github.head_ref }}
21+
22+
- name: Pint
23+
uses: aglipanci/laravel-pint-action@2.5
24+
25+
- name: Commit changes
26+
uses: stefanzweifel/git-auto-commit-action@v5
27+
with:
28+
commit_message: Fix styling

.github/workflows/run-tests.yml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: run-tests
2+
3+
on:
4+
push:
5+
paths:
6+
- '**.php'
7+
- '.github/workflows/run-tests.yml'
8+
- 'phpunit.xml.dist'
9+
- 'composer.json'
10+
- 'composer.lock'
11+
12+
concurrency:
13+
group: ${{ github.workflow }}-${{ github.ref }}
14+
cancel-in-progress: true
15+
16+
jobs:
17+
test:
18+
runs-on: ${{ matrix.os }}
19+
timeout-minutes: 5
20+
strategy:
21+
fail-fast: true
22+
matrix:
23+
os: [ubuntu-latest, windows-latest]
24+
php: [8.4, 8.3, 8.2]
25+
laravel: [12.*]
26+
include:
27+
- laravel: 12.*
28+
testbench: 10.*
29+
30+
name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.os }}
31+
32+
steps:
33+
- name: Checkout code
34+
uses: actions/checkout@v4
35+
36+
- name: Setup PHP
37+
uses: shivammathur/setup-php@v2
38+
with:
39+
php-version: ${{ matrix.php }}
40+
coverage: none
41+
42+
- name: Setup problem matchers
43+
run: |
44+
echo "::add-matcher::${{ runner.tool_cache }}/php.json"
45+
echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
46+
47+
- name: Install dependencies
48+
run: |
49+
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update
50+
composer update --prefer-dist --no-interaction
51+
52+
- name: List Installed Dependencies
53+
run: composer show -D
54+
55+
- name: Execute tests
56+
run: vendor/bin/pest --parallel --ci

.gitignore

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Composer Related
2+
composer.lock
3+
/vendor
4+
5+
# Frontend Assets
6+
/node_modules
7+
8+
# Logs
9+
npm-debug.log
10+
yarn-error.log
11+
12+
# Caches
13+
.phpunit.cache
14+
.phpunit.result.cache
15+
/build
16+
17+
# IDE Helper
18+
_ide_helper.php
19+
_ide_helper_models.php
20+
.phpstorm.meta.php
21+
22+
# Editors
23+
/.idea
24+
/.fleet
25+
/.vscode
26+
27+
# Misc
28+
phpunit.xml
29+
phpstan.neon
30+
testbench.yaml
31+
/docs
32+
/coverage

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Changelog
2+
3+
All notable changes to `laravel-dependency-aware-cache` will be documented in this file.

LICENSE.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Copyright © 2008 by Yii Software (https://www.yiiframework.com/) All rights reserved.
2+
Copyright © 2025 by Pixel & Tonic, Inc. All rights reserved.
3+
4+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
5+
6+
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
7+
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
8+
Neither the name of Yii Software nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
9+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

README.md

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# Dependency-aware cache for Laravel
2+
3+
[![Latest Version on Packagist](https://img.shields.io/packagist/v/craftcms/laravel-dependency-aware-cache.svg?style=flat-square)](https://packagist.org/packages/craftcms/laravel-dependency-aware-cache)
4+
[![GitHub Tests Action Status](https://img.shields.io/github/actions/workflow/status/craftcms/laravel-dependency-aware-cache/run-tests.yml?branch=main&label=tests&style=flat-square)](https://github.com/craftcms/laravel-dependency-aware-cache/actions?query=workflow%3Arun-tests+branch%3Amain)
5+
[![GitHub Code Style Action Status](https://img.shields.io/github/actions/workflow/status/craftcms/laravel-dependency-aware-cache/fix-php-code-style-issues.yml?branch=main&label=code%20style&style=flat-square)](https://github.com/craftcms/laravel-dependency-aware-cache/actions?query=workflow%3A"Fix+PHP+code+style+issues"+branch%3Amain)
6+
[![Total Downloads](https://img.shields.io/packagist/dt/craftcms/laravel-dependency-aware-cache.svg?style=flat-square)](https://packagist.org/packages/craftcms/laravel-dependency-aware-cache)
7+
8+
An implementation of [Yii's cache with dependencies](https://github.com/yiisoft/cache) for Laravel
9+
10+
## Installation
11+
12+
You can install the package via composer:
13+
14+
```bash
15+
composer require craftcms/laravel-dependency-aware-cache
16+
```
17+
18+
## Usage
19+
20+
The dependency aware repository is hooked up automatically and will be returned when using the `Cache` Facade.
21+
22+
This package also provides a `\Craft\DependencyAwareCache\Facades\DependencyCache` Facade which extends the default `Cache` Facade but provides updated docblocks.
23+
24+
```php
25+
use Illuminate\Support\Facades\Cache;
26+
use Craft\DependencyAwareCache\Facades\DependencyCache;
27+
28+
/** @var DependencyAwareRepository $cache */
29+
$cache = Cache::store();
30+
31+
/** @var DependencyAwareRepository $cache */
32+
$cache = DependencyCache::store();
33+
```
34+
35+
### Invalidation
36+
37+
When using the cache, you can specify a dependency that may trigger cache invalidation. Below is an example using the tag dependency:
38+
39+
```php
40+
use Craft\DependencyAwareCache\Dependency\TagDependency;
41+
use Illuminate\Support\Facades\Cache;
42+
43+
Cache::put('item_42_price', 10, null, new TagDependency('item_42'));
44+
Cache::put('item_42_total', 100, null, new TagDependency('item_42'));
45+
46+
Cache::get('item_42_price'); // 10
47+
Cache::get('item_42_total'); // 100
48+
49+
TagDependency::invalidate('item_42');
50+
51+
Cache::get('item_42_price'); // null
52+
Cache::get('item_42_total'); // null
53+
```
54+
55+
Other dependencies:
56+
57+
- `Craft\DependencyAwareCache\Dependency\CallbackDependency` - invalidates when the result of a callback changes.
58+
- `Craft\DependencyAwareCache\Dependency\FileDependency` - invalidates the cache based on file modification time.
59+
- `Craft\DependencyAwareCache\Dependency\ValueDependency` - invalidates the cache when specified value changes.
60+
61+
- You may combine multiple dependencies using `Craft\DependencyAwareCache\Dependency\AnyDependency` or `Craft\DependencyAwareCache\Dependency\AllDependencies`.
62+
63+
You can implement your own dependency by extending `Craft\DependencyAwareCache\Dependency\Dependency`.
64+
65+
## Testing
66+
67+
```bash
68+
composer test
69+
```
70+
71+
## Changelog
72+
73+
Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.
74+
75+
## Contributing
76+
77+
Please see [CONTRIBUTING](CONTRIBUTING.md) for details.
78+
79+
## Security Vulnerabilities
80+
81+
Please review [our security policy](../../security/policy) on how to report security vulnerabilities.
82+
83+
## Credits
84+
85+
- [Pixel & Tonic](https://github.com/craftcms)
86+
- [Yii Software](https://www.yiiframework.com/)
87+
- [All Contributors](../../contributors)
88+
89+
## License
90+
91+
Please see [License File](LICENSE.md) for more information.

composer.json

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
{
2+
"name": "craftcms/laravel-dependency-aware-cache",
3+
"description": "A dependency aware cache repository for Laravel",
4+
"keywords": [
5+
"craftcms",
6+
"laravel",
7+
"cache"
8+
],
9+
"homepage": "https://github.com/craftcms/laravel-dependency-aware-cache",
10+
"license": "BSD-3-Clause",
11+
"authors": [
12+
{
13+
"name": "Pixel & Tonic",
14+
"homepage": "https://pixelandtonic.com/"
15+
}
16+
],
17+
"require": {
18+
"php": "^8.2",
19+
"illuminate/contracts": "^10.0||^11.0||^12.0",
20+
"illuminate/cache": "^10.0||^11.0||^12.0"
21+
},
22+
"require-dev": {
23+
"laravel/pint": "^1.14",
24+
"nunomaduro/collision": "^8.1.1||^7.10.0",
25+
"larastan/larastan": "^2.9||^3.0",
26+
"orchestra/testbench": "^10.0.0||^9.0.0||^8.22.0",
27+
"pestphp/pest": "^3.0",
28+
"pestphp/pest-plugin-arch": "^3.0",
29+
"pestphp/pest-plugin-laravel": "^3.0",
30+
"phpstan/extension-installer": "^1.3||^2.0",
31+
"phpstan/phpstan-deprecation-rules": "^1.1||^2.0",
32+
"phpstan/phpstan-phpunit": "^1.3||^2.0"
33+
},
34+
"autoload": {
35+
"psr-4": {
36+
"Craft\\DependencyAwareCache\\": "src/"
37+
}
38+
},
39+
"autoload-dev": {
40+
"psr-4": {
41+
"Craft\\DependencyAwareCache\\Tests\\": "tests/"
42+
}
43+
},
44+
"scripts": {
45+
"post-autoload-dump": "@composer run prepare",
46+
"prepare": "@php vendor/bin/testbench package:discover --ansi",
47+
"analyse": "vendor/bin/phpstan analyse",
48+
"test": "vendor/bin/pest",
49+
"test-coverage": "vendor/bin/pest --coverage",
50+
"format": "vendor/bin/pint"
51+
},
52+
"config": {
53+
"sort-packages": true,
54+
"allow-plugins": {
55+
"pestphp/pest-plugin": true,
56+
"phpstan/extension-installer": true
57+
}
58+
},
59+
"extra": {
60+
"laravel": {
61+
"providers": [
62+
"Craft\\DependencyAwareCache\\CacheServiceProvider"
63+
],
64+
"aliases": {
65+
"DependencyCache": "Craft\\DependencyAwareCache\\Facades\\DependencyCache"
66+
}
67+
}
68+
},
69+
"minimum-stability": "dev",
70+
"prefer-stable": true
71+
}

0 commit comments

Comments
 (0)