Skip to content

Commit

Permalink
feat(cache): Added PbCache class and enabled cache for controllers / c…
Browse files Browse the repository at this point in the history
…lose #32
  • Loading branch information
anibalealvarezs committed Feb 17, 2022
1 parent b90ac75 commit 1337b6b
Show file tree
Hide file tree
Showing 19 changed files with 964 additions and 221 deletions.
14 changes: 11 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,26 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [1.3.7] - 2022-02-13
## [1.3.7.1] - 2022-02-14

- Implemented cache for controllers
- Added facades por ```PbDebugbar``` class

## [1.3.7] - 2022-02-14

- BREAKING CHANGES:
- [x] [1.3.6.1]
- Added Middleware to store config data in session
- Helpers renamed as Utilities
- Helpers moved from classes to functions in helpers.php file
- Helpers moved from classes to functions in ```helpers.php``` file
- ```Helpers``` folder renamed as ```Utilities```
- ```PbHelpers``` class renamed as ```PbUtilities```
- Added singleton for utilities
- CRUD permitions refactored
- Performance significantly improved
- ```crud``` attribute is now optional for models
- Added performance flags to CRUD controllers
- Added facades por ```PbUtilities``` class
- Overrides moved to ```Overrides``` folder

## [1.3.6.1] - 2022-02-11

Expand Down
8 changes: 6 additions & 2 deletions src/Controllers/Config/PbConfigController.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
use Auth;
use DB;
use Inertia\Response as InertiaResponse;
use Psr\SimpleCache\InvalidArgumentException;
use ReflectionException;
use Session;

class PbConfigController extends PbBuilderController
Expand All @@ -42,6 +44,7 @@ function __construct(Request $request, $crud_perms = false)
*
* @param string $route
* @return InertiaResponse|JsonResponse
* @throws ReflectionException|InvalidArgumentException
*/
public function create(string $route = 'level'): InertiaResponse|JsonResponse
{
Expand Down Expand Up @@ -70,14 +73,15 @@ public function store(Request $request): Redirector|RedirectResponse|Application
* @param null $element
* @param bool $multiple
* @param string $route
* @return InertiaResponse|JsonResponse
* @return RedirectResponse|InertiaResponse|JsonResponse
* @throws ReflectionException|InvalidArgumentException
*/
public function edit(
int $id,
$element = null,
bool $multiple = false,
string $route = 'level'
): InertiaResponse|JsonResponse {
): RedirectResponse|InertiaResponse|JsonResponse {

$this->pushRequired(['configkey']);

Expand Down
27 changes: 26 additions & 1 deletion src/Controllers/Navigation/PbNavigationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

use Anibalealvarezs\Projectbuilder\Controllers\PbBuilderController;

use Anibalealvarezs\Projectbuilder\Facades\PbDebugbarFacade as Debug;
use Anibalealvarezs\Projectbuilder\Utilities\PbCache;
use App\Http\Requests;

use Illuminate\Http\JsonResponse;
Expand All @@ -14,6 +16,8 @@
use Auth;
use DB;
use Inertia\Response as InertiaResponse;
use Psr\SimpleCache\InvalidArgumentException;
use ReflectionException;
use Session;

class PbNavigationController extends PbBuilderController
Expand Down Expand Up @@ -58,6 +62,7 @@ function __construct(Request $request, $crud_perms = false)
* @param bool $multiple
* @param string $route
* @return InertiaResponse|JsonResponse|RedirectResponse
* @throws ReflectionException|InvalidArgumentException
*/
public function index(
int $page = 1,
Expand All @@ -69,13 +74,33 @@ public function index(
bool $multiple = false,
string $route = 'level'): InertiaResponse|JsonResponse|RedirectResponse
{
Debug::start('custom_controller', $this->vars->level->names.' crud controller');

Debug::measure(
$this->vars->level->names.' crud controller - model list build',
function() use (&$model, $page, $perpage, $orderby, $field, $order) {
$cached = PbCache::run(
closure: fn() => $this->vars->level->modelPath::withPublicRelations()->orderedByDefault()->get(),
package: $this->vars->helper->package,
class: __CLASS__,
model: $this->vars->level->names,
modelFunction: 'getList',
byRoles: true,
);
$model = $cached['data'];
$this->vars->cacheObjects[] = $cached['index'];
}
);

Debug::stop('custom_controller');

return parent::index(
$page,
$perpage,
$orderby,
$field,
$order,
$this->vars->level->modelPath::withPublicRelations()->orderedByDefault()->get()
$model
);
}
}
Loading

0 comments on commit 1337b6b

Please sign in to comment.