How to set lifetime for doctrine result and query cache globally? - doctrine

Is it possible to set lifetime for doctrine result and query cache globally (not second level cache). I do not want do it for every query, like below:
$queryBuilder
->getQuery()
->useResultCache(true)
->setQueryCacheLifetime(7 * 24 * 60 * 60)
->setResultCacheLifetime(7 * 24 * 60 * 60)
->getSingleScalarResult()

Related

How to fixed issue whiule creating cookie in laravel?

I am using Laravel 8 my cookie function not create cookie in browser. My code is
public function connectWoocommerce(Request $request)
{
Cookie::queue('site_url', $request->site_url, time() + (10 * 365 * 24 * 60 * 60));
Cookie::queue('key', $request->consumer_key, time() + (10 * 365 * 24 * 60 * 60));
Cookie::queue('secret', $request->consumer_secret, time() + (10 * 365 * 24 * 60 * 60));
dd($request->all());
}
How can solve it thanks.
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class middleware is responsible for setting queued cookies to the response. Make sure to have it in you $middleware list.
It will not be called if you terminate the script from anywhere within your controller.

Problem with cron job which has to run every 15 minutes but not at 15,30,45

So i have a cron job that runs and executes fine (hence why no path is shown) at:
*/15 * * * *
but I don't want that as it means it runs at every fifteen minutes past 0 of the hour according to crontab.guru which gives tasks run at 15,30 and 45 minutes.
This is actually what I want:
1/15 * * * *
which according to crontab.guru should begin the 15 minutes at 1 minute past the hour and run the tasks at 16, 31 and 46 minutes.
Now the problem is when I crontab -e to set up the cron job of 1/15 * * * * I get a bad minute error from crontab, yet as i say in my opening lines using */15 * * * * returns no error from crontab and the task is executed. Why is this?.
You could do 1,16,31,46 * * * * to run the jobs at 1, 16, 31 and 46 minutes every hour.

How to set two cron on the same springboot method?

I want to set a timer at 9:00 / 16:30. But one cron can not realize it.
So i need two cron to realize it. The corn is as follows:
cron1: * 30 16 * * *
cron2: * * 9 * * *
I want to set cron by springboot #Schedule like this
#Scheduled(cron = "0 0 2 * * ?")
public void sayHello(){}
But it seems that can not support two #Scheduled label on one method or two cron in one label.
The so low method is as follow, Any better advice?
#Scheduled(cron = "* 30 16 * * ?")
public void sayHello(){}
#Scheduled(cron = "* * 9 * * ?")
public void subSayHello(){sayHello();}
I think it is difficult because of the different min and different hour,
if the cron run in the same hour or min, it will be easy.
Such as:
"* 0,30 9 * * ?"
"* 0 9,16 * * ?"
Or you can see this link Cron expression to run job twice a day at different time?

Sprng Boot #Scheduled task stopped working after cron change

Spring Boot here. I have a scheduled background task that I kick off every hour on the hour:
#Component
public class TokenReaper {
#Scheduled(cron = "0 0 * * * *")
public void fire() {
// Doesn't matter what it does...
}
}
I actually need it to now run only at 8:26 AM every day, so only once a day at that time (strange, I know!), so I change the cron expression to:
#Component
public class TokenReaper {
#Scheduled(cron = "0 26 8 * * *")
public void fire() {
// Doesn't matter what it does...
}
}
After making this change, the task stops running at 8:26 AM, and because of the logs I can't tell when its actually running or if its actually running at all! Can anyone see if my new cron expression is somehow malformed or not correctly set to run at 8:26 AM each and every morning?!
You need to add ? in your cron expression by:
Changing #Scheduled(cron = "0 26 8 * * *") into:
#Scheduled(cron = "0 26 8 * * ?")
Try this
#Scheduled(cron = "0 26 8 * * ?")
Cron expression is represented by six fields:
second, minute, hour, day of month, month, day(s) of week
Example patterns
* "0 0 * * * *" = the top of every hour of every day.
* "*/10 * * * * *" = every ten seconds.
* "0 0 8-10 * * *" = 8, 9 and 10 o'clock of every day.
* "0 0 8,10 * * *" = 8 and 10 o'clock of every day.
* "0 0/30 8-10 * * *" = 8:00, 8:30, 9:00, 9:30 and 10 o'clock every day.
* "0 0 9-17 * * MON-FRI" = on the hour nine-to-five weekdays
* "0 0 0 25 12 ?" = every Christmas Day at midnight

How to set scheduler task in spring to run every 1 minutes

now I have this configuration my my scheduler:
<task:scheduled ref="task" method="run" cron="0 45 22 * * *" />
when this task is executed ? and how I can change it to do this task every minute
This task is executed at 22:45:00 every day, every week, every month.
To execute a task every minute, use
0 * * * * *
The accepted answer is correct for spring. Other than that, one should be careful whether the target system uses 6 or 5-digits cron.
With 5-digits-crons
0 * * * * schedules to be run "at minute 0" (hence every hour).
The correct answer in this case should be either
* * * * *
or
*/1 * * * *
Also see: Spring cron vs normal cron?

Resources