Although I couldn't find anything on it, I thought I would double check - does memcache support transactions?
If not, which I'm betting is the likely answer, then what is the correct method to work with memcache in an environment with transactions? Wouldn't you have to read from the DB every time you plan to update, even if the data is in cache, just so you can set your locks? For example, a script that updates some data would look like this:
I think you have to update cache after you run your update query, in case you hit a deadlock and need to rollback. But you should also update cache before committing, in case any other thread is waiting to read your data and may accidentally update it's cache with even newer data before you, resulting in your now-out-of-date data overwriting it.
Is this the correct sequence of steps? Is there any way to not have to hit the db on reads for update?
Redis uses a single core and shows better performance than Memcached in storing small datasets when measured in terms of cores. Memcached implements a multi-threaded architecture by utilizing multiple cores. Therefore, for storing larger datasets, Memcached can perform better than Redis.
From the memcached wiki: When the table is full, subsequent inserts cause older data to be purged in least recently used (LRU) order.
Just a note: as it was confirmed by the current maintainer on Twitter, Memcached is still actively developed / maintained.
How does Memcached work? Unlike databases that store data on disk or SSDs, Memcached keeps its data in memory. By eliminating the need to access disks, in-memory key-value stores such as Memcached avoid seek time delays and can access data in microseconds.
Memcache does have an operator called CAS (Check And Set - or Compare And Swap) which may help you. The PHP manual has some documentation on it, Memcached::cas, but it should also be supported in other libraries and languages.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With