Skip to content

Commit 962cf11

Browse files
authored
Merge pull request #32 from kettasoft/feat/caching
Add filterable caching system with auto-invalidation.
2 parents a410275 + 3761bf8 commit 962cf11

20 files changed

+7313
-7
lines changed

config/filterable.php

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -729,4 +729,136 @@
729729
*/
730730
'enabled' => env('FILTERABLE_EVENTS_ENABLED', true),
731731
],
732+
733+
/*
734+
|--------------------------------------------------------------------------
735+
| Caching System
736+
|--------------------------------------------------------------------------
737+
|
738+
| Configure the filterable caching system, which intelligently caches
739+
| filtered query results to improve performance for frequently-used filters.
740+
|
741+
*/
742+
'cache' => [
743+
744+
/*
745+
|--------------------------------------------------------------------------
746+
| Enable or Disable Caching
747+
|--------------------------------------------------------------------------
748+
|
749+
| This option allows you to enable or disable the caching system globally.
750+
| When disabled, no caching will occur even if explicitly requested in code.
751+
|
752+
*/
753+
'enabled' => env('FILTERABLE_CACHE_ENABLED', true),
754+
755+
/*
756+
|--------------------------------------------------------------------------
757+
| Default Cache Driver
758+
|--------------------------------------------------------------------------
759+
|
760+
| The cache driver to use for storing filterable results.
761+
| You can use any Laravel cache driver: redis, memcached, file, etc.
762+
| Defaults to the application's default cache driver if not specified.
763+
|
764+
*/
765+
'driver' => env('FILTERABLE_CACHE_DRIVER', null),
766+
767+
/*
768+
|--------------------------------------------------------------------------
769+
| Default Cache TTL (Time To Live)
770+
|--------------------------------------------------------------------------
771+
|
772+
| The default time in seconds that cached results will be stored.
773+
| This can be overridden on a per-filter basis using cache($ttl).
774+
|
775+
*/
776+
'default_ttl' => env('FILTERABLE_CACHE_TTL', 3600), // 1 hour
777+
778+
/*
779+
|--------------------------------------------------------------------------
780+
| Cache Key Prefix
781+
|--------------------------------------------------------------------------
782+
|
783+
| A prefix prepended to all cache keys generated by the filterable system.
784+
| This helps organize cache entries and avoid key collisions.
785+
|
786+
*/
787+
'prefix' => env('FILTERABLE_CACHE_PREFIX', 'filterable'),
788+
789+
/*
790+
|--------------------------------------------------------------------------
791+
| Cache Key Version
792+
|--------------------------------------------------------------------------
793+
|
794+
| A version string included in cache keys. Increment this to invalidate
795+
| all existing cached entries after deploying breaking changes to filters.
796+
|
797+
*/
798+
'version' => env('FILTERABLE_CACHE_VERSION', 'v1'),
799+
800+
/*
801+
|--------------------------------------------------------------------------
802+
| Cache Profiles
803+
|--------------------------------------------------------------------------
804+
|
805+
| Define reusable cache profiles with predefined TTL and tags.
806+
| These can be used via cacheProfile('profile_name') for consistency.
807+
|
808+
| Example:
809+
| 'profiles' => [
810+
| 'heavy_reports' => [
811+
| 'ttl' => 7200,
812+
| 'tags' => ['reports', 'analytics'],
813+
| ],
814+
| 'quick_filters' => [
815+
| 'ttl' => 300,
816+
| 'tags' => ['filters'],
817+
| ],
818+
| ],
819+
|
820+
*/
821+
'profiles' => [
822+
// Define your cache profiles here
823+
],
824+
825+
/*
826+
|--------------------------------------------------------------------------
827+
| Auto-Invalidation
828+
|--------------------------------------------------------------------------
829+
|
830+
| Automatically invalidate cached results when related models are modified.
831+
| Maps model classes to cache tags that should be flushed on changes.
832+
|
833+
| Example:
834+
| 'auto_invalidate' => [
835+
| 'enabled' => true,
836+
| 'models' => [
837+
| App\Models\Post::class => ['posts', 'content'],
838+
| App\Models\User::class => ['users'],
839+
| ],
840+
| ],
841+
|
842+
*/
843+
'auto_invalidate' => [
844+
'enabled' => env('FILTERABLE_AUTO_INVALIDATE', false),
845+
'models' => [
846+
// Define model-to-tags mappings here
847+
],
848+
],
849+
850+
/*
851+
|--------------------------------------------------------------------------
852+
| Cache Tracking
853+
|--------------------------------------------------------------------------
854+
|
855+
| Enable tracking of cache hit/miss statistics for monitoring and
856+
| performance optimization. Requires profiler to be enabled.
857+
|
858+
*/
859+
'tracking' => [
860+
'enabled' => env('FILTERABLE_CACHE_TRACKING', false),
861+
'log_channel' => env('FILTERABLE_CACHE_LOG_CHANNEL', 'daily'),
862+
],
863+
],
732864
];

docs/.vuepress/config.js

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ export default defineUserConfig({
4343
"/cli/inspect.md",
4444
],
4545
},
46+
{
47+
text: "Advanced",
48+
children: ["/caching/overview"],
49+
},
4650
],
4751
sidebar: [
4852
{
@@ -136,7 +140,7 @@ export default defineUserConfig({
136140
],
137141
},
138142
{
139-
text: "API",
143+
text: "API Reference",
140144
collapsible: true,
141145
children: [
142146
{
@@ -157,6 +161,48 @@ export default defineUserConfig({
157161
},
158162
],
159163
},
164+
{
165+
text: "Caching",
166+
collapsible: true,
167+
children: [
168+
{
169+
text: "Overview",
170+
link: "caching/overview",
171+
},
172+
{
173+
text: "Getting Started",
174+
link: "caching/getting-started",
175+
},
176+
{
177+
text: "Strategies",
178+
link: "caching/strategies",
179+
},
180+
{
181+
text: "Auto Invalidation",
182+
link: "caching/auto-invalidation",
183+
},
184+
{
185+
text: "Cache Profiles",
186+
link: "caching/profiles",
187+
},
188+
{
189+
text: "Scoping Cache",
190+
link: "caching/scoping",
191+
},
192+
{
193+
text: "Monitoring Cached Items",
194+
link: "caching/monitoring",
195+
},
196+
{
197+
text: "API Reference",
198+
link: "caching/api-reference",
199+
},
200+
{
201+
text: "Examples",
202+
link: "caching/examples",
203+
},
204+
],
205+
},
160206
{
161207
text: "CLI",
162208
collapsible: true,

0 commit comments

Comments
 (0)