@@ -6,7 +6,6 @@ InspireCMS implements multiple caching layers to optimize performance. This guid
66
77Caching in InspireCMS accelerates content delivery by storing frequently accessed data in fast-access storage. The system employs several caching strategies:
88
9- - ** Content Cache** : Speeds up content retrieval
109- ** Navigation Cache** : Makes menu loading faster
1110- ** Route Cache** : Improves URL resolution
1211- ** Template Cache** : Accelerates template rendering
@@ -80,56 +79,6 @@ InspireCMS uses Laravel's caching system. Configure the cache driver in `config/
8079],
8180```
8281
83- ## Content Caching
84-
85- InspireCMS automatically caches content to reduce database queries.
86-
87- ### Content Cache Configuration
88-
89- Adjust content cache settings:
90-
91- ``` php
92- // config/inspirecms.php
93- 'cache' => [
94- 'content' => [
95- 'enabled' => true,
96- 'ttl' => 3600, // 1 hour in seconds
97- 'per_user' => false, // Whether to cache content per user
98- ],
99- ],
100- ```
101-
102- ### Content Cache Tags
103-
104- Content is cached with tags for easy invalidation:
105-
106- - ` content:{id} ` - Individual content item
107- - ` content:type:{type} ` - All content of a specific type
108- - ` content:lang:{lang} ` - Content in a specific language
109-
110- Example of accessing cached content:
111-
112- ``` php
113- use Illuminate\Support\Facades\Cache;
114-
115- // Get content with fallback to database
116- $content = Cache::tags(['content:123'])->remember('content:123', 3600, function () {
117- return InspireCmsConfig::getContentModelClass()::find(123);
118- });
119- ```
120-
121- ### Invalidating Content Cache
122-
123- Automatically invalidated when content is updated, but can also be cleared manually:
124-
125- ``` php
126- // Clear cache for a specific content item
127- Cache::tags(['content:123'])->flush();
128-
129- // Clear cache for all content of a specific type
130- Cache::tags(['content:type:blog'])->flush();
131- ```
132-
13382## Navigation Caching
13483
13584Navigation structure is cached for improved performance.
@@ -162,9 +111,6 @@ Clear the navigation cache manually:
162111``` php
163112// Clear all navigation cache
164113\SolutionForest\InspireCms\Facades\InspireCms::forgetCachedNavigation();
165-
166- // Clear category-specific cache
167- Cache::forget("inspirecms.navigation.main.en");
168114```
169115
170116## Route Caching
@@ -188,7 +134,13 @@ InspireCMS caches content routes for faster URL resolution.
188134In addition to Laravel's route caching, clear InspireCMS route cache:
189135
190136``` bash
191- php artisan inspirecms:clear-route-cache
137+ php artisan route:clear
138+ ```
139+
140+ or
141+
142+ ``` bash
143+ php artisan inspirecms:clear-cache --routes
192144```
193145
194146## Template Caching
@@ -237,14 +189,27 @@ Cache model queries directly:
237189
238190``` php
239191use Illuminate\Support\Facades\Cache;
192+ use SolutionForest\InspireCms\InspireCmsConfig;
240193
241194// Get all published blog posts, cached for 1 hour
242195$posts = Cache::remember('published_blog_posts', 3600, function () {
243- return InspireCmsConfig::getContentModelClass()::whereDocumentType('blog')
196+ return InspireCmsConfig::getContentModelClass()::query()
197+ ->whereHas('documentType' => fn ($q) => $q->where('slug', 'blog'))
244198 ->whereIsPublished()
245199 ->latest()
246200 ->get();
247201});
202+
203+ // Or via service
204+ $posts = Cache::remember('published_blog_posts', 3600, function () {
205+ return inspirecms_content()->getUnderRealPath(
206+ path: 'home/blogs',
207+ isPublished: true,
208+ sorting: [
209+ '__latest_version_dt' => 'desc',
210+ ]
211+ );
212+ });
248213```
249214
250215### Query Cache Considerations
@@ -371,14 +336,13 @@ class WarmCacheCommand extends Command
371336
372337 public function handle()
373338 {
374- $this->info('Warming content cache...');
375-
339+ // Warm language
340+ $this->info('Warming language cache...')
341+ $langs = inspirecms()->getAllAvailableLanguages();
342+
376343 // Warm main navigation
377344 $this->info('Warming navigation cache...');
378- foreach (inspirecms()->getAllAvailableLanguages() as $locale => $lang) {
379- inspirecms()->getNavigation('main', $locale);
380- $this->info("Cached main navigation for {$locale}");
381- }
345+ inspirecms()->getNavigation('main');
382346
383347 // Warm homepage and main sections
384348 $this->info('Warming content cache...');
@@ -444,12 +408,12 @@ InspireCMS provides specific commands for clearing various caches:
444408
445409``` bash
446410# Clear all InspireCMS caches
447- php artisan inspirecms:clear-cache
411+ php artisan inspirecms:clear-cache --all
448412
449413# Clear specific caches
450- php artisan inspirecms:clear-language- cache
451- php artisan inspirecms:clear-route- cache
452- php artisan inspirecms:clear-navigation- cache
414+ php artisan inspirecms:clear-cache --languages
415+ php artisan inspirecms:clear-cache --routes
416+ php artisan inspirecms:clear-cache --navigation
453417```
454418
455419### Automatic Cache Clearing
0 commit comments