Files
yii2/tests/framework/log/ArrayTarget.php
Carsten Brandt 711498f93a Cache user assignments to avoid unnecessary DB queries (#14696)
* Cache user assignments to avoid unnecessary DB queries

alternative to #9138 and #10981, only cache on `checkAccess` call which is usually
called on every request. Cache is not necessary in RBAC management.

Similar to #14061 but includes proper cache invalidation and test.

`getAssignments()` always queries the DB. The cache is only applied on
`checkAccess` calls, and invalidated as soon as the RBAC structure is
modified through the manager component (verified by the test case).

Regarding [concerns of memory usage](https://github.com/yiisoft/yii2/pull/14061#issuecomment-297982502)
if used in batch mode on multiple users, you can call
`invalidateCache()` method if this really causes a problem.

fixes #7743
close #9138
close #14061
close #10981

See also
- https://github.com/yiisoft/yii2/issues/7626#issuecomment-77745166
- https://github.com/yiisoft/yii2/pull/14061#issuecomment-319645488

* improve test naming

* fix tests

* fix assignment cache for non-scalar user-ids
2017-09-01 10:50:36 +02:00

24 lines
487 B
PHP

<?php
namespace yiiunit\framework\log;
use yii\base\Exception;
use yii\log\Target;
/**
* ArrayTarget logs messages into an array, useful for tracking data in tests.
*/
class ArrayTarget extends Target
{
public $exportInterval = 1000000;
/**
* Exports log [[messages]] to a specific destination.
*/
public function export()
{
// throw exception if message limit is reached
throw new Exception('More than 1000000 messages logged.');
}
}