File tree Expand file tree Collapse file tree 3 files changed +7
-7
lines changed Expand file tree Collapse file tree 3 files changed +7
-7
lines changed Original file line number Diff line number Diff line change @@ -14,16 +14,16 @@ class CacheHandler implements CacheHandlerContract
14
14
* Cache policies for the given model.
15
15
*
16
16
* @param Rule $model The model to cache policies for.
17
- * @return Query The cached query or a new query if caching is disabled.
17
+ * @return Query|Rule The cached query if caching is disabled, or origin Rule .
18
18
*/
19
- public function cachePolicies (Rule $ model ): Query
19
+ public function cachePolicies (Rule $ model ): Query | Rule
20
20
{
21
21
if ($ this ->config ('cache.enabled ' , false )) {
22
22
$ key = $ this ->config ('cache.key ' , 'tauthz ' );
23
23
$ expire = $ this ->config ('cache.expire ' , 0 );
24
24
return $ model ->cache ($ key , $ expire );
25
25
} else {
26
- return $ model-> newQuery () ;
26
+ return $ model ;
27
27
}
28
28
}
29
29
}
Original file line number Diff line number Diff line change 7
7
8
8
interface CacheHandlerContract
9
9
{
10
- public function cachePolicies (Rule $ model ): Query ;
10
+ public function cachePolicies (Rule $ model ): Query | Rule ;
11
11
}
Original file line number Diff line number Diff line change @@ -358,17 +358,17 @@ public function testCachePolicies()
358
358
$ start = microtime (true );
359
359
Enforcer::loadPolicy ();
360
360
$ end = microtime (true );
361
- $ timeEnabled = $ end - $ start ;
361
+ $ timeDisabled = $ end - $ start ;
362
362
// time cost if cache is disabled
363
363
$ driver = config ('tauthz.default ' );
364
364
config (['enforcers ' => [$ driver => [
365
- 'cache ' => ['enabled ' => false ],
365
+ 'cache ' => ['enabled ' => true ],
366
366
'database ' => ['rules_name ' => 'rules ' ]
367
367
]]], 'tauthz ' );
368
368
$ start = microtime (true );
369
369
Enforcer::loadPolicy ();
370
370
$ end = microtime (true );
371
- $ timeDisabled = $ end - $ start ;
371
+ $ timeEnabled = $ end - $ start ;
372
372
// ensure time cost is not greater than time cost if cache is disabled
373
373
$ this ->assertTrue ($ timeEnabled < $ timeDisabled );
374
374
});
You can’t perform that action at this time.
0 commit comments