Answer the question
In order to leave comments, you need to log in
Is it possible to reliably increment an array element in the Laravel cache?
Good afternoon colleagues.
There was such a question. There is an array in the Laravel cache, in the code I get it by key, increase the value of some element and put it back into the cache.
Is it safe to do this, or with a large number of simultaneous requests, I will lose data when the same array is taken from the cache in several threads, for each I increment the counter, put it back into the caches and some of the data will be lost in the end.
UPD 1. The cache is stored in APC.
Thanks in advance for your reply!
Answer the question
In order to leave comments, you need to log in
Atomically like this php.net/manual/en/function.apc-inc.php
Read, increment in the code and write back - no, you will lose data. What's wrong with Laravel - get to the bottom of the low-level apc function and you'll know.
Need to make a connection
public function children()
{
return $this->hasMany('Comment', 'parent_id', 'id');
}
Nested set will make it easier for you to work with this kind of data, and here is the implementation under Lara https://github.com/etrepat/baum
There are a lot of rakes in the implementation through parent_id if there are a lot of entities and nesting is unlimited
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question