P
P
Pavel Osipov2017-03-07 20:31:35
Laravel
Pavel Osipov, 2017-03-07 20:31:35

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

3 answer(s)
M
Melkij, 2017-03-07
@melkij

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.

N
Nikita Dergachov, 2017-12-05
@vanillathunder

Need to make a connection

public function children()
{
     return $this->hasMany('Comment', 'parent_id', 'id');
}

And the request to execute And in the view to check whether there is a parent.

I
Ilya Gerasimov, 2017-12-05
@Omashu

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 question

Ask a Question

731 491 924 answers to any question