Now, I use default cache for all:
'cache' => [
'class' => 'yii\caching\FileCache',
],
And I use nodge eauth for registration users.
Default config nodge:
'components' => [
'eauth' => array(
'class' => 'nodge\eauth\EAuth',
'popup' => true, // Use the popup window instead of redirecting.
'cache' => false, // Cache component name or false to disable cache. Defaults to 'cache' on production environments.
'cacheExpire' => 0, // Cache lifetime. Defaults to 0 - means unlimited.
)
]
What should I specify to cache?
If you want to cache requests, your config should be
'eauth' => [
'class' => 'nodge\eauth\EAuth',
'popup' => false, // Use the popup window instead of redirecting.
'cache' => 'cache', // Cache component name or false to disable cache. Defaults to 'cache' on production environments.
'cacheExpire' => 0, // Cache lifetime. Defaults to 0 - means unlimited.]
But I can be wrong.
Related
Hello everyone I work with cakephp3 here is my cache configuration in app.php
'Cache' => [
'access_token' => [
'className' => 'File',
'duration' => '+2 minutes',
'path' => CACHE
]
],
I set the duration to 2 minutes but I need to dynamically change the duration via my Controller.
I I tried setConfig but it does not work
Cache::write("access_token_$key", $response, 'access_token');
Cache::setConfig("access_token_$key", array('duration' => $time));
Also i tried this but still does not work
$engine = Cache::engine("access_token_$key");
$engine->config("duration", $time);
Thanks for any help
I am implementing page cache for one of my page. For depenedency, I have to check an array, which can be either exist or not. Possible array keys cane ,
usersearch['id'], usersearch['name'], usersearch['phone]. I have to add dependency for any change in these values as well.
Also, I have to clear cache for any update or add in user table.
Is there any possible solution for this.?
Thanks in advance
You can use variations
public function behaviors(){
$usersearch = Yii::$app->requst->get('usersearch');
return [
[
'class' => 'yii\filters\PageCache',
'only' => ['index'],
'duration' => 60,
'variations' => [
'YOUR_DYNAMIC_VALUE1','YOUR_DYNAMIC_VALUE2'
],
'dependency' => [
'class' => 'yii\caching\DbDependency',
'sql' => 'SELECT COUNT(*) FROM post',
],
],
];
}
Ref link
IN YOUR CASE ,you can use
'variations' => \Yii::$app->requst->get('usersearch')??[],
or
'variations' => [
\/Yii::$app->requst->get('usersearch')['id'] ?? '',
\Yii::$app->requst->get('usersearch')['name'] ?? '',
\Yii::$app->requst->get('usersearch')['phone'] ?? '',
]
You could use a yii\caching\FileCache component with the following configuration.
Firstly, you set the cache in the init function of your controller:
Yii::$app->setComponents([
'yourCacheName' => [
'class' => \yii\caching\FileCache::class,
'defaultDuration' => 1800, //cache duration in seconds
'keyPrefix' => Yii::$app->getSession()->getId(). '_'
]
]);
Here, the parameter keyPrefix is set so that it is linked to the session ID. Thus, the visitors do not see each other's cached page. If the content is static and equal, regardless of the user or the session, this parameter can be removed.
In the view that must be cached you can call the beginCache function and the dependency as follows:
$this->beginCache('cache-id', [
'cache' => Yii::$app->yourCacheName, // the name of the component as set before
'variations' => [
$usersearch['id'] ?? '',
$usersearch['name'] ?? '',
$usersearch['phone'] ?? '',
],
'dependency' => [
'class' => \yii\caching\DbDependency::class,
'sql' => 'SELECT count(*) FROM your_user_table'
]
]);
// your view
$this->endCache();
I'm working on Laravel 5.1.46 (LTS) with rabbitmq for message queues with package
.env
QUEUE_DRIVER=rabbitmq
config/queue.php
'rabbitmq' => [
'driver' => 'rabbitmq',
'host' => env('RABBITMQ_HOST', '127.0.0.1'),
'port' => env('RABBITMQ_PORT', 5672),
'vhost' => env('RABBITMQ_VHOST', '/'),
'login' => env('RABBITMQ_LOGIN', 'guest'),
'password' => env('RABBITMQ_PASSWORD', 'guest'),
// name of the default queue,
'queue' => env('RABBITMQ_QUEUE'),
// create the exchange if not exists
'exchange_declare' => true,
// create the queue if not exists and bind to the exchange
'queue_declare_bind' => true,
'queue_params' => [
'passive' => false,
'durable' => true, // false
'exclusive' => false,
'auto_delete' => false,
],
'exchange_params' => [
// more info at http://www.rabbitmq.com/tutorials/amqp-concepts.html
'type' => env('RABBITMQ_EXCHANGE_TYPE', 'direct'),
'passive' => false,
// the exchange will survive server restarts
'durable' => true, // fakse
'auto_delete' => false,
]
I've 8 queues in total. Queue names are stored in .env file.
QUEUE_ONE=queue-one
QUEUE_TWO=queue-two
.
.
.
QUEUE_EIGHT=queue-eight
And while dispatching a job,
dispatch(new Job1())->onQueue(env('QUEUE_ONE'))
Queues and messages are persistent/durable.
Due to some performance issues, I need to change the durability of some queues and their messages. So,
5 queues and their messages will be transient (non-persistent)
3 queues and their messages will be persistent
How it is possible with-in Laravel and rabbitmq ?
Note :
I know, I can set
durable = false
but it will be for all queues,
// config/queue.php
'rabbitmq_durable' => [
'driver' => 'rabbitmq',
// ...
'queue_params' => [
'passive' => false,
'durable' => true,
'exclusive' => false,
'auto_delete' => false,
],
// ...
],
'rabbitmq_not_durable' => [
'driver' => 'rabbitmq',
// ...
'queue_params' => [
'passive' => false,
'durable' => false,
'exclusive' => false,
'auto_delete' => false,
],
// ...
]
Laravel 5.1
To use different configs and different connections on Laravel 5.1 you have to use the Queue fascade:
Queue::connection('rabbitmq_durable')->pushOn('queue_1', TestJob::class);
Queue::connection('rabbitmq_not_durable')->pushOn('queue_6', TestJob::class);
Laravel 5.2+
To use different configs and different connections on Laravel 5.2 and onwards you can use the onConnection() method like so:
TestJob::dispatch()->onQueue('queue_one')->onConnection('rabbitmq_durable');
TestJob::dispatch()->onQueue('queue_six')->onConnection('rabbitmq_not_durable');
I have already added these codes in my config/web file
'user' => [
'identityClass' => 'app\models\User',
'enableAutoLogin' => true,
'enableSession' => true,
'authTimeout' =>86400,
'loginUrl' => ['account/login'],
],
'session' => [
'timeout' => 86400,
],
After session expires I want to automatically logout and redirect to login action.
Make sure in your php.ini file
config
session.gc_maxlifetime
by default set as :
session.gc_maxlifetime=1440
change it, to :
session.gc_maxlifetime=86400
Very first you have to set 'enableAutoLogin' => false, .
now add these lines there in your config/web.
I have added it in frontend/config/main.php because I am using frontend only.
'components' => [
...
'user' => [
'identityClass' => 'common\models\User',
'enableAutoLogin' => false,
'enableSession' => true,
'authTimeout' => 1800, //30 minutes
'identityCookie' => ['name' => '_identity-frontend', 'httpOnly' => true],
],
'session' => [
// this is the name of the session cookie used for login on the frontend
'class' => 'yii\web\Session',
'name' => 'advanced-frontend',
'timeout' => 1800,
],
...
Now go to yii2/web/User.php and write code for destroy session in logout method before return as guest()-
public function logout($destroySession = true)
{
$identity = $this->getIdentity();
if ($identity !== null && $this->beforeLogout($identity)) {
......
if ($destroySession && $this->enableSession) {
Yii::$app->getSession()->destroy();
}
$this->afterLogout($identity);
}
$session = Yii::$app->session;
$session->remove('other.id');
$session->remove('other.name');
// (or) if is optional if above won't works
unset($_SESSION['class.id']);
unset($_SESSION['class.name']);
// (or) if is optional if above won't works
unset($session['other.id']);
unset($session['other.name']);
return $this->getIsGuest();
}
For me it worked great.
I'm trying to continue the CakePHP session outside the application.
The CakePHP session config:
Configure::write('Session', array(
'checkAgent' => false,
'defaults' => 'cake',
'timeout' => 10080, // 1 week,
'ini' => array(
'session.cookie_httponly' => 1,
)
));
cakephp_webroot/test_session.php:
<?php
session_name("CAKEPHP");
session_start();
var_dump($_SESSION);
?>
test session.php should output the cake session, but it is not working. I've verified the cookie CAKEPHP is present.
You are using the cake defaults for session handling, they are not compatible with the PHP defaults (available as php for the defaults option).
The cake configuration uses a custom save path and enforces cookie usage.
https://github.com/cakephp/.../Datasource/CakeSession.php#L600-L612
// ...
'cake' => array(
'cookie' => 'CAKEPHP',
'timeout' => 240,
'ini' => array(
'session.use_trans_sid' => 0,
'url_rewriter.tags' => '',
'session.serialize_handler' => 'php',
'session.use_cookies' => 1,
'session.cookie_path' => self::$path,
'session.save_path' => TMP . 'sessions',
'session.save_handler' => 'files'
)
),
// ...
So either configure your external scripts session usage the same as the cake defaults, or use the php defaults instead, and control things via your PHP ini configuration.
See also
Cookbook > Development > Sessions > Built-in Session handlers & configuration
http://php.net/manual/en/session.configuration.php