Yanz Mini Shell
[_]
[-]
[X]
[
HomeShell 1
] [
HomeShell 2
] [
Upload
] [
Command Shell
] [
Scripting
] [
About
]
[ Directory ] =>
/
home
admin
web
uyoxpress.com
public_html
Action
[*]
New File
[*]
New Folder
Sensitive File
[*]
/etc/passwd
[*]
/etc/shadow
[*]
/etc/resolv.conf
[
Delete
] [
Edit
] [
Rename
] [
Back
]
laravel-eloquent-query-cache/.codecov.yml 0000644 00000000400 15007532600 0014443 0 ustar 00 codecov: notify: require_ci_to_pass: yes coverage: precision: 2 round: down range: "70...100" status: project: yes patch: yes changes: no comment: layout: "reach, diff, flags, files, footer" behavior: default require_changes: no laravel-eloquent-query-cache/composer.json 0000644 00000002552 15007532600 0014754 0 ustar 00 { "name": "rennokki/laravel-eloquent-query-cache", "description": "Adding cache on your Laravel Eloquent queries' results is now a breeze.", "keywords": [ "laravel", "caching", "eloquent", "remember", "query", "sql" ], "license": "Apache-2.0", "homepage": "https://github.com/renoki-co/laravel-eloquent-query-cache", "authors": [ { "name": "Alex Renoki", "email": "alex@renoki.org", "homepage": "https://github.com/rennokki", "role": "Developer" } ], "require": { "illuminate/database": "^9.35|^10.5", "illuminate/support": "^9.35|^10.5" }, "autoload": { "psr-4": { "Rennokki\\QueryCache\\": "src/" } }, "autoload-dev": { "psr-4": { "Rennokki\\QueryCache\\Test\\": "tests" } }, "scripts": { "test": "vendor/bin/phpunit" }, "require-dev": { "chelout/laravel-relationship-events": "^1.5|^2.0", "laravel/legacy-factories": "^1.3", "livewire/livewire": "dev-master", "mockery/mockery": "^1.5", "orchestra/testbench": "^7.23|^8.1.1", "phpunit/phpunit": "^9.5.25" }, "config": { "sort-packages": true }, "prefer-stable": true, "minimum-stability": "dev" } laravel-eloquent-query-cache/CONTRIBUTING.md 0000644 00000005634 15007532600 0014467 0 ustar 00 # Contributing Contributions are **welcome** and will be fully **credited**. Please read and understand the contribution guide before creating an issue or pull request. ## Etiquette This project is open source, and as such, the maintainers give their free time to build and maintain the source code held within. They make the code freely available in the hope that it will be of use to other developers. It would be extremely unfair for them to suffer abuse or anger for their hard work. Please be considerate towards maintainers when raising issues or presenting pull requests. Let's show the world that developers are civilized and selfless people. It's the duty of the maintainer to ensure that all submissions to the project are of sufficient quality to benefit the project. Many developers have different skillsets, strengths, and weaknesses. Respect the maintainer's decision, and do not be upset or abusive if your submission is not used. ## Viability When requesting or submitting new features, first consider whether it might be useful to others. Open source projects are used by many developers, who may have entirely different needs to your own. Think about whether or not your feature is likely to be used by other users of the project. ## Procedure Before filing an issue: - Attempt to replicate the problem, to ensure that it wasn't a coincidental incident. - Check to make sure your feature suggestion isn't already present within the project. - Check the pull requests tab to ensure that the bug doesn't have a fix in progress. - Check the pull requests tab to ensure that the feature isn't already in progress. Before submitting a pull request: - Check the codebase to ensure that your feature doesn't already exist. - Check the pull requests to ensure that another person hasn't already submitted the feature or fix. ## Requirements If the project maintainer has any additional requirements, you will find them listed here. - **[PSR-2 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)** - The easiest way to apply the conventions is to install [PHP Code Sniffer](https://pear.php.net/package/PHP_CodeSniffer). - **Add tests!** - Your patch won't be accepted if it doesn't have tests. - **Document any change in behaviour** - Make sure the `README.md` and any other relevant documentation are kept up-to-date. - **Consider our release cycle** - We try to follow [SemVer v2.0.0](https://semver.org/). Randomly breaking public APIs is not an option. - **One pull request per feature** - If you want to do more than one thing, send multiple pull requests. - **Send coherent history** - Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please [squash them](https://www.git-scm.com/book/en/v2/Git-Tools-Rewriting-History#Changing-Multiple-Commit-Messages) before submitting. **Happy coding**! laravel-eloquent-query-cache/LICENSE 0000644 00000026107 15007532600 0013241 0 ustar 00 Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright Renoki Co. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. laravel-eloquent-query-cache/.github/stale.yml 0000644 00000001125 15007532600 0015420 0 ustar 00 # Number of days of inactivity before an issue becomes stale daysUntilStale: 29 # Number of days of inactivity before a stale issue is closed daysUntilClose: 1 # Issues with these labels will never be considered stale exemptLabels: - pinned - security # Label to use when marking an issue as stale staleLabel: wontfix # Comment to post when marking an issue as stale. Set to `false` to disable markComment: false # Comment to post when closing a stale issue. Set to `false` to disable closeComment: > This issue has been automatically closed because it has not had any recent activity. 😨 laravel-eloquent-query-cache/.github/workflows/ci.yml 0000644 00000003323 15007532600 0016742 0 ustar 00 name: CI on: push: branches: - '*' tags: - '*' pull_request: branches: - '*' jobs: build: runs-on: ubuntu-latest strategy: fail-fast: false matrix: php: - '8.1' - '8.2' laravel: - 9.* - 10.* prefer: - 'prefer-lowest' - 'prefer-stable' include: - laravel: 9.* testbench: 7.* - laravel: 10.* testbench: 8.* name: PHP ${{ matrix.php }} - Laravel ${{ matrix.laravel }} --${{ matrix.prefer }} steps: - uses: actions/checkout@v3 - name: Setup PHP uses: shivammathur/setup-php@v2 with: php-version: ${{ matrix.php }} extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv coverage: pcov - uses: actions/cache@v3.0.11 name: Cache dependencies with: path: ~/.composer/cache/files key: composer-php-${{ matrix.php }}-${{ matrix.laravel }}-${{ matrix.prefer }}-${{ hashFiles('composer.json') }} - name: Install dependencies run: | composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update composer update --${{ matrix.prefer }} --prefer-dist --no-interaction --no-suggest - name: Run tests run: | CACHE_DRIVER=array vendor/bin/phpunit --coverage-text --coverage-clover=coverage_array.xml CACHE_DRIVER=file vendor/bin/phpunit --coverage-text --coverage-clover=coverage_file.xml - uses: codecov/codecov-action@v3.1.1 with: fail_ci_if_error: false file: '*.xml' laravel-eloquent-query-cache/.github/dependabot.yml 0000644 00000000430 15007532600 0016413 0 ustar 00 version: 2 updates: - package-ecosystem: github-actions directory: "/" schedule: interval: weekly open-pull-requests-limit: 10 - package-ecosystem: composer directory: "/" schedule: interval: weekly open-pull-requests-limit: 10 versioning-strategy: increase laravel-eloquent-query-cache/.github/FUNDING.yml 0000644 00000000021 15007532600 0015374 0 ustar 00 github: rennokki laravel-eloquent-query-cache/README.md 0000644 00000004322 15007532600 0013506 0 ustar 00 Laravel Eloquent Query Cache ============================  [](https://codecov.io/gh/renoki-co/laravel-eloquent-query-cache/branch/master) [](https://github.styleci.io/repos/223236785) [](https://packagist.org/packages/rennokki/laravel-eloquent-query-cache) [](https://packagist.org/packages/rennokki/laravel-eloquent-query-cache) [](https://packagist.org/packages/rennokki/laravel-eloquent-query-cache) [](https://packagist.org/packages/rennokki/laravel-eloquent-query-cache) Laravel Eloquent Query Cache brings back the `remember()` functionality that has been removed from Laravel a long time ago. It adds caching functionalities directly on the Eloquent level, making use of cache within your database queries. ## 🤝 Supporting **If you are using one or more Renoki Co. open-source packages in your production apps, in presentation demos, hobby projects, school projects or so, sponsor our work with [Github Sponsors](https://github.com/sponsors/rennokki). 📦** [<img src="https://github-content.s3.fr-par.scw.cloud/static/37.jpg" height="210" width="418" />](https://github-content.renoki.org/github-repo/37) ## 📃 Documentation [The entire documentation is available on Gitbook 🌍](https://rennokki.gitbook.io/laravel-eloquent-query-cache/) ## 🐛 Testing ``` bash vendor/bin/phpunit ``` ## 🤝 Contributing Please see [CONTRIBUTING](CONTRIBUTING.md) for details. ## 🔒 Security If you discover any security related issues, please email alex@renoki.org instead of using the issue tracker. ## 🎉 Credits - [Alex Renoki](https://github.com/rennokki) - [All Contributors](../../contributors) laravel-eloquent-query-cache/src/Query/Builder.php 0000644 00000002420 15007532600 0016217 0 ustar 00 <?php namespace Rennokki\QueryCache\Query; use Illuminate\Database\Query\Builder as BaseBuilder; use Illuminate\Support\Arr; use Rennokki\QueryCache\Contracts\QueryCacheModuleInterface; use Rennokki\QueryCache\Traits\QueryCacheModule; class Builder extends BaseBuilder implements QueryCacheModuleInterface { use QueryCacheModule; /** * {@inheritdoc} */ public function get($columns = ['*']) { return $this->shouldAvoidCache() ? parent::get($columns) : $this->getFromQueryCache('get', Arr::wrap($columns)); } /** * {@inheritdoc} */ public function useWritePdo() { // Do not cache when using the write pdo for query. $this->dontCache(); // Call parent method parent::useWritePdo(); return $this; } /** * Add a subselect expression to the query. * * @param \Closure|$this|string $query * @param string $as * @return $this * * @throws \InvalidArgumentException */ public function selectSub($query, $as) { if (! is_string($query) && get_class($query) == self::class) { $this->appendCacheTags($query->getCacheTags() ?? []); } return parent::selectSub($query, $as); } } laravel-eloquent-query-cache/src/Traits/QueryCacheable.php 0000644 00000010110 15007532600 0017642 0 ustar 00 <?php namespace Rennokki\QueryCache\Traits; use Rennokki\QueryCache\FlushQueryCacheObserver; use Rennokki\QueryCache\Query\Builder; /** * @method static bool flushQueryCache(array $tags = []) * @method static bool flushQueryCacheWithTag(string $string) * @method static \Illuminate\Database\Query\Builder|static cacheFor(\DateTime|int|null $time) * @method static \Illuminate\Database\Query\Builder|static cacheForever() * @method static \Illuminate\Database\Query\Builder|static dontCache() * @method static \Illuminate\Database\Query\Builder|static doNotCache() * @method static \Illuminate\Database\Query\Builder|static cachePrefix(string $prefix) * @method static \Illuminate\Database\Query\Builder|static cacheTags(array $cacheTags = []) * @method static \Illuminate\Database\Query\Builder|static appendCacheTags(array $cacheTags = []) * @method static \Illuminate\Database\Query\Builder|static cacheDriver(string $cacheDriver) * @method static \Illuminate\Database\Query\Builder|static cacheBaseTags(array $tags = []) */ trait QueryCacheable { /** * Boot the trait. * * @return void */ public static function bootQueryCacheable() { /** @var \Illuminate\Database\Eloquent\Model $this */ if (isset(static::$flushCacheOnUpdate) && static::$flushCacheOnUpdate) { static::observe( static::getFlushQueryCacheObserver() ); } } /** * Get the observer class name that will * observe the changes and will invalidate the cache * upon database change. * * @return string */ protected static function getFlushQueryCacheObserver() { return FlushQueryCacheObserver::class; } /** * Set the base cache tags that will be present * on all queries. * * @return array */ protected function getCacheBaseTags(): array { return [ (string) static::class, ]; } /** * When invalidating automatically on update, you can specify * which tags to invalidate. * * @param string|null $relation * @param \Illuminate\Database\Eloquent\Collection|null $pivotedModels * @return array */ public function getCacheTagsToInvalidateOnUpdate($relation = null, $pivotedModels = null): array { /** @var \Illuminate\Database\Eloquent\Model $this */ return $this->getCacheBaseTags(); } /** * {@inheritdoc} */ protected function newBaseQueryBuilder() { /** @var \Illuminate\Database\Eloquent\Model $this */ $connection = $this->getConnection(); $builder = new Builder( $connection, $connection->getQueryGrammar(), $connection->getPostProcessor() ); $builder->dontCache(); if (property_exists($this, 'cacheFor')) { $builder->cacheFor($this->cacheFor); } if (method_exists($this, 'cacheForValue')) { $builder->cacheFor($this->cacheForValue($builder)); } if (property_exists($this, 'cacheTags')) { $builder->cacheTags($this->cacheTags); } if (method_exists($this, 'cacheTagsValue')) { $builder->cacheTags($this->cacheTagsValue($builder)); } if (property_exists($this, 'cachePrefix')) { $builder->cachePrefix($this->cachePrefix); } if (method_exists($this, 'cachePrefixValue')) { $builder->cachePrefix($this->cachePrefixValue($builder)); } if (property_exists($this, 'cacheDriver')) { $builder->cacheDriver($this->cacheDriver); } if (method_exists($this, 'cacheDriverValue')) { $builder->cacheDriver($this->cacheDriverValue($builder)); } if (property_exists($this, 'cacheUsePlainKey')) { $builder->withPlainKey(); } if (method_exists($this, 'cacheUsePlainKeyValue')) { $builder->withPlainKey($this->cacheUsePlainKeyValue($builder)); } return $builder->cacheBaseTags($this->getCacheBaseTags()); } } laravel-eloquent-query-cache/src/Traits/QueryCacheModule.php 0000644 00000022764 15007532600 0020206 0 ustar 00 <?php namespace Rennokki\QueryCache\Traits; use BadMethodCallException; use DateTime; trait QueryCacheModule { /** * The number of seconds or the DateTime instance * that specifies how long to cache the query. * * @var int|\DateTime */ protected $cacheFor; /** * The tags for the query cache. Can be useful * if flushing cache for specific tags only. * * @var null|array */ protected $cacheTags = null; /** * The tags for the query cache that * will be present on all queries. * * @var null|array */ protected $cacheBaseTags = null; /** * The cache driver to be used. * * @var string */ protected $cacheDriver; /** * A cache prefix string that will be prefixed * on each cache key generation. * * @var string */ protected $cachePrefix = 'leqc'; /** * Specify if the key that should be used when caching the query * need to be plain or be hashed. * * @var bool */ protected $cacheUsePlainKey = false; /** * Set if the caching should be avoided. * * @var bool */ protected $avoidCache = true; /** * Get the cache from the current query. * * @param string $method * @param array $columns * @param string|null $id * @return array */ public function getFromQueryCache(string $method = 'get', array $columns = ['*'], string $id = null) { if (is_null($this->columns)) { $this->columns = $columns; } $key = $this->getCacheKey($method); $cache = $this->getCache(); $callback = $this->getQueryCacheCallback($method, $columns, $id); $time = $this->getCacheFor(); if ($time instanceof DateTime || $time > 0) { return $cache->remember($key, $time, $callback); } return $cache->rememberForever($key, $callback); } /** * Get the query cache callback. * * @param string $method * @param array|string $columns * @param string|null $id * @return \Closure */ public function getQueryCacheCallback(string $method = 'get', $columns = ['*'], string $id = null) { return function () use ($method, $columns) { $this->avoidCache = true; return $this->{$method}($columns); }; } /** * Get a unique cache key for the complete query. * * @param string $method * @param string|null $id * @param string|null $appends * @return string */ public function getCacheKey(string $method = 'get', string $id = null, string $appends = null): string { $key = $this->generateCacheKey($method, $id, $appends); $prefix = $this->getCachePrefix(); return "{$prefix}:{$key}"; } /** * Generate the unique cache key for the query. * * @param string $method * @param string|null $id * @param string|null $appends * @return string */ public function generateCacheKey(string $method = 'get', string $id = null, string $appends = null): string { $key = $this->generatePlainCacheKey($method, $id, $appends); if ($this->shouldUsePlainKey()) { return $key; } return hash('sha256', $key); } /** * Generate the plain unique cache key for the query. * * @param string $method * @param string|null $id * @param string|null $appends * @return string */ public function generatePlainCacheKey(string $method = 'get', string $id = null, string $appends = null): string { $name = $this->connection->getName(); // Count has no Sql, that's why it can't be used ->toSql() if ($method === 'count') { return $name.$method.$id.serialize($this->getBindings()).$appends; } return $name.$method.$id.$this->toSql().serialize($this->getBindings()).$appends; } /** * Flush the cache that contains specific tags. * * @param array $tags * @return bool */ public function flushQueryCache(array $tags = []): bool { $cache = $this->getCacheDriver(); if (! method_exists($cache, 'tags')) { return false; } if (! $tags) { $tags = $this->getCacheBaseTags(); } foreach ($tags as $tag) { $this->flushQueryCacheWithTag($tag); } return true; } /** * Flush the cache for a specific tag. * * @param string $tag * @return bool */ public function flushQueryCacheWithTag(string $tag): bool { $cache = $this->getCacheDriver(); try { return $cache->tags($tag)->flush(); } catch (BadMethodCallException $e) { return $cache->flush(); } } /** * Indicate that the query results should be cached. * * @param \DateTime|int|null $time * @return \Rennokki\QueryCache\Traits\QueryCacheModule */ public function cacheFor($time) { $this->cacheFor = $time; $this->avoidCache = $time === null; return $this; } /** * Indicate that the query results should be cached forever. * * @return \Illuminate\Database\Query\Builder|static */ public function cacheForever() { return $this->cacheFor(-1); } /** * Indicate that the query should not be cached. * * @param bool $avoidCache * @return \Illuminate\Database\Query\Builder|static */ public function dontCache(bool $avoidCache = true) { $this->avoidCache = $avoidCache; return $this; } /** * Alias for dontCache(). * * @param bool $avoidCache * @return \Illuminate\Database\Query\Builder|static */ public function doNotCache(bool $avoidCache = true) { return $this->dontCache($avoidCache); } /** * Set the cache prefix. * * @param string $prefix * @return \Rennokki\QueryCache\Traits\QueryCacheModule */ public function cachePrefix(string $prefix) { $this->cachePrefix = $prefix; return $this; } /** * Attach tags to the cache. * * @param array $cacheTags * @return \Rennokki\QueryCache\Traits\QueryCacheModule */ public function cacheTags(array $cacheTags = []) { $this->cacheTags = $cacheTags; return $this; } /** * Append tags to the cache. * * @param array $cacheTags * @return \Rennokki\QueryCache\Traits\QueryCacheModule */ public function appendCacheTags(array $cacheTags = []) { $this->cacheTags = array_unique(array_merge($this->cacheTags ?? [], $cacheTags)); return $this; } /** * Use a specific cache driver. * * @param string $cacheDriver * @return \Rennokki\QueryCache\Traits\QueryCacheModule */ public function cacheDriver(string $cacheDriver) { $this->cacheDriver = $cacheDriver; return $this; } /** * Set the base cache tags; the tags * that will be present on all cached queries. * * @param array $tags * @return \Rennokki\QueryCache\Traits\QueryCacheModule */ public function cacheBaseTags(array $tags = []) { $this->cacheBaseTags = $tags; return $this; } /** * Use a plain key instead of a hashed one in the cache driver. * * @param bool $usePlainKey * @return \Rennokki\QueryCache\Traits\QueryCacheModule */ public function withPlainKey(bool $usePlainKey = true) { $this->cacheUsePlainKey = $usePlainKey; return $this; } /** * Get the cache driver. * * @return \Illuminate\Cache\CacheManager */ public function getCacheDriver() { return app('cache')->driver($this->cacheDriver); } /** * Get the cache object with tags assigned, if applicable. * * @return \Illuminate\Cache\CacheManager */ public function getCache() { $cache = $this->getCacheDriver(); $tags = array_merge( $this->getCacheTags() ?: [], $this->getCacheBaseTags() ?: [] ); try { return $tags ? $cache->tags($tags) : $cache; } catch (BadMethodCallException $e) { return $cache; } } /** * Check if the cache operation should be avoided. * * @return bool */ public function shouldAvoidCache(): bool { return $this->avoidCache; } /** * Check if the cache operation key should use a plain * query key. * * @return bool */ public function shouldUsePlainKey(): bool { return $this->cacheUsePlainKey; } /** * Get the cache time attribute. * * @return int|\DateTime */ public function getCacheFor() { return $this->cacheFor; } /** * Get the cache tags attribute. * * @return array|null */ public function getCacheTags() { return $this->cacheTags; } /** * Get the base cache tags attribute. * * @return array|null */ public function getCacheBaseTags() { return $this->cacheBaseTags; } /** * Get the cache prefix attribute. * * @return string */ public function getCachePrefix(): string { return $this->cachePrefix; } } laravel-eloquent-query-cache/src/FlushQueryCacheObserver.php 0000644 00000010437 15007532600 0020276 0 ustar 00 <?php namespace Rennokki\QueryCache; use Exception; use Illuminate\Database\Eloquent\Model; class FlushQueryCacheObserver { /** * Handle the Model "created" event. * * @param \Illuminate\Database\Eloquent\Model $model * @return void */ public function created(Model $model) { $this->invalidateCache($model); } /** * Handle the Model "updated" event. * * @param \Illuminate\Database\Eloquent\Model $model * @return void */ public function updated(Model $model) { $this->invalidateCache($model); } /** * Handle the Model "deleted" event. * * @param \Illuminate\Database\Eloquent\Model $model * @return void */ public function deleted(Model $model) { $this->invalidateCache($model); } /** * Handle the Model "forceDeleted" event. * * @param \Illuminate\Database\Eloquent\Model $model * @return void */ public function forceDeleted(Model $model) { $this->invalidateCache($model); } /** * Handle the Model "restored" event. * * @param \Illuminate\Database\Eloquent\Model $model * @return void */ public function restored(Model $model) { $this->invalidateCache($model); } /** * Invalidate attach for belongsToMany. * * @param string $relation * @param \Illuminate\Database\Eloquent\Model $model * @param array $ids * @return void */ public function belongsToManyAttached($relation, Model $model, $ids) { $this->invalidateCache($model, $relation, $model->{$relation}()->findMany($ids)); } /** * Invalidate detach for belongsToMany. * * @param string $relation * @param \Illuminate\Database\Eloquent\Model $model * @param array $ids * @return void */ public function belongsToManyDetached($relation, Model $model, $ids) { $this->invalidateCache($model, $relation, $model->{$relation}()->findMany($ids)); } /** * Invalidate update pivot for belongsToMany. * * @param string $relation * @param \Illuminate\Database\Eloquent\Model $model * @param array $ids * @return void */ public function belongsToManyUpdatedExistingPivot($relation, Model $model, $ids) { $this->invalidateCache($model, $relation, $model->{$relation}()->findMany($ids)); } /** * Invalidate attach for morphToMany. * * @param string $relation * @param \Illuminate\Database\Eloquent\Model $model * @param array $ids * @return void */ public function morphToManyAttached($relation, Model $model, $ids) { $this->invalidateCache($model, $relation, $model->{$relation}()->findMany($ids)); } /** * Invalidate detach for morphToMany. * * @param string $relation * @param \Illuminate\Database\Eloquent\Model $model * @param array $ids * @return void */ public function morphToManyDetached($relation, Model $model, $ids) { $this->invalidateCache($model, $relation, $model->{$relation}()->findMany($ids)); } /** * Invalidate update pivot for morphToMany. * * @param string $relation * @param \Illuminate\Database\Eloquent\Model $model * @param array $ids * @return void */ public function morphToManyUpdatedExistingPivot($relation, Model $model, $ids) { $this->invalidateCache($model, $relation, $model->{$relation}()->findMany($ids)); } /** * Invalidate the cache for a model. * * @param \Illuminate\Database\Eloquent\Model $model * @param string|null $relation * @param \Illuminate\Database\Eloquent\Collection|null $pivotedModels * @return void * * @throws Exception */ protected function invalidateCache(Model $model, $relation = null, $pivotedModels = null): void { $class = get_class($model); $tags = $model->getCacheTagsToInvalidateOnUpdate($relation, $pivotedModels); if (! $tags) { throw new Exception('Automatic invalidation for '.$class.' works only if at least one tag to be invalidated is specified.'); } $class::flushQueryCache($tags); } } laravel-eloquent-query-cache/src/Contracts/QueryCacheModuleInterface.php 0000644 00000001274 15007532600 0022512 0 ustar 00 <?php namespace Rennokki\QueryCache\Contracts; interface QueryCacheModuleInterface { /** * Generate the plain unique cache key for the query. * * @param string $method * @param string|null $id * @param string|null $appends * @return string */ public function generatePlainCacheKey(string $method = 'get', string $id = null, string $appends = null): string; /** * Get the query cache callback. * * @param string $method * @param array|string $columns * @param string|null $id * @return \Closure */ public function getQueryCacheCallback(string $method = 'get', $columns = ['*'], string $id = null); } laravel-eloquent-query-cache/.styleci.yml 0000644 00000000017 15007532600 0014501 0 ustar 00 preset: laravel
Free Space : Byte