Skip to content

Commit

Permalink
added blade cache system to Page Speed Optimization
Browse files Browse the repository at this point in the history
added clear cache to settings
  • Loading branch information
A1Gard committed Oct 9, 2024
1 parent bf44225 commit c4f5662
Show file tree
Hide file tree
Showing 18 changed files with 142 additions and 6 deletions.
6 changes: 6 additions & 0 deletions app/Helpers/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -1418,3 +1418,9 @@ function findArea($name,$model = null)
}
return \App\Models\Area::where('name', $name)->first();
}


function cacheNumber()
{
return getSetting('cache_number');
}
14 changes: 13 additions & 1 deletion app/Http/Controllers/Admin/SettingController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use App\Models\Menu;
use App\Models\Setting;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Artisan;

class SettingController extends Controller
{
Expand All @@ -18,7 +19,7 @@ class SettingController extends Controller
public function index()
{
//
$settings = Setting::where('active', 1)
$settings = Setting::where('active', true)
->orderBy('section')->get(); //ESH// just active setting`s show
$cats = Category::all(['id','name']);
$menus = Menu::all(['id','name']);
Expand Down Expand Up @@ -108,4 +109,15 @@ public function destroy(Setting $setting)
{
//
}

public function cacheClear(){
$f = Setting::where('key','cache_number')->first();
$f->value += 1;
$f->save();
Artisan::call('cache:clear');
Artisan::call('config:clear');
Artisan::call('view:clear');
Artisan::call('route:clear');
return redirect()->back()->with(['message' => __('Cache cleared')]);
}
}
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"laravel/ui": "^4.5",
"pishran/zarinpal": "^4.3",
"plank/laravel-metable": "^6.0",
"ryangjchandler/blade-cache-directive": "^1.0",
"spatie/laravel-medialibrary": "^11.4",
"spatie/laravel-permission": "^6.7",
"spatie/laravel-tags": "^4.6",
Expand Down
76 changes: 75 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions config/blade-cache-directive.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

return [

'enabled' => env('BLADE_CACHE_DIRECTIVE_ENABLED', true),

'ttl' => env('BLADE_CACHE_DIRECTIVE_TTL', 3600),

];
8 changes: 8 additions & 0 deletions database/seeders/SettingSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,13 @@ public function run(): void
'type' => 'CHECKBOX',
'value' => 0,
],
[
'title' => __('Cache'),
'key' => 'cache_number',
'type' => 'TEXT',
'value' => 0,
'active' => false,
],

],
'SMS' => [
Expand Down Expand Up @@ -223,6 +230,7 @@ public function run(): void
$setting->value = $set['value'] ?? null;
$setting->type = $set['type'] ?? 'TEXT';
$setting->ltr = $set['ltr'] ?? false;
$setting->active = $set['active'] ?? true;
$setting->is_basic = true;
$setting->size = $set['size'] ?? 12;;
$setting->save();
Expand Down
6 changes: 6 additions & 0 deletions resources/views/admin/commons/setting.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@
{{__("Recommends")}}
</li>
</ul>

<div class="p-2">
<a href="{{ route('admin.setting.cache-clear') }}" class="btn btn-secondary d-block">
{{__("Clear caches")}}
</a>
</div>
</div>

<div class="item-list mb-3">
Expand Down
8 changes: 5 additions & 3 deletions resources/views/layouts/app.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@

<div>
<div id="panel">
<aside>
@include('components.panel-side-navbar')
</aside>
@cache('navbar_panel'. cacheNumber())
<aside>
@include('components.panel-side-navbar')
</aside>
@endcache
<div id="sidebar-panel"></div>
<main class="py-3 px-3">
@include('components.panel-breadcrumb')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@cache('follow_us'. cacheNumber(), 90)
<section id='FollowUsSocial'>
<span>
{{__("Follow us")}}
Expand All @@ -8,3 +9,4 @@
</a>
@endforeach
</section>
@endcache
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@cache('go_top'. cacheNumber())
<a id='SimpleGoTop' href="#">
<i class="{{getSetting($data->area_name.'_'.$data->part.'_icon')}}"></i>
</a>
@endcache
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@cache('wave_footer'. cacheNumber(), 90)
<footer class='FireFooter'>
<div class="footer">
<div class="bubbles">
Expand Down Expand Up @@ -315,3 +316,4 @@
</defs>
</svg>
</footer>
@endcache
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@cache('parallax_footer'. cacheNumber(), 90)
<footer class='ParallaxFooter' style="background-image: url('{{asset('upload/images/'.$data->area_name.'.'.$data->part.'.jpg')}}')">
<div class="{{gfx()['container']}}">
<div class="row">
Expand Down Expand Up @@ -44,3 +45,4 @@
{{getSetting('copyright')}}
</p>
</footer>
@endcache
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@cache('simple_footer'. cacheNumber(), 90)
<section class='SimpleFooter'>
<div class="content">
<div class="{{gfx()['container']}}">
Expand Down Expand Up @@ -52,3 +53,4 @@
</p>
</div>
</section>
@endcache
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

@cache('wave_footer'. cacheNumber(), 90)
<footer class='WaveFooter'
style="--speed: {{getSetting($data->area_name.'_'.$data->part.'_speed')}}s;
--speed2: {{getSetting($data->area_name.'_'.$data->part.'_speed2')}}s;
Expand Down Expand Up @@ -46,3 +46,4 @@
{{getSetting('copyright')}} </div>
</div>
</footer>
@endcache
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@cache('post_sidebar_2'. cacheNumber(), 90)
<aside class="p-4">
<h4>
{{__("Search")}}
Expand Down Expand Up @@ -42,3 +43,4 @@
@endforeach
</ul>
</aside>
@endcache
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@cache('post_sidebar1'. cacheNumber(), 90)
<aside class="p-4">
<h4>
{{__("Search")}}
Expand Down Expand Up @@ -42,3 +43,4 @@
@endforeach
</ul>
</aside>
@endcache
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<aside class="mt-2">
@cache('product_sidebar'. cacheNumber(), 90)
<div class="side-item">
<h4>
{{__("Search")}}
Expand All @@ -22,6 +23,7 @@
</ul>
</div>
</div>
@endcache
<div class="side-item">
<h4>
{{__("Filter")}}
Expand Down
1 change: 1 addition & 0 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@ function () {
Route::get('index', [\App\Http\Controllers\Admin\SettingController::class, "index"])->name('index');
Route::post('store', [\App\Http\Controllers\Admin\SettingController::class, "store"])->name('store');
Route::post('update', [\App\Http\Controllers\Admin\SettingController::class, "update"])->name('update');
Route::get('cache/clear', [\App\Http\Controllers\Admin\SettingController::class, "cacheClear"])->name('cache-clear');
}
);
Route::prefix('gfx')->name('gfx.')->group(
Expand Down

0 comments on commit c4f5662

Please sign in to comment.