Is memcached all about deadlines?

I believe that the standard way to cache something using mamcached is to insert an object into the cache for a certain period of time, for example.

memcli:set(key, rows_array, 5 * 60) 

Is there a better way to cache things in which the cache will be checked inside the database to see if the data has changed, rather than relying on a timer that can cause synchronization problems?

I will use PHP.

+6
php caching memcached
source share
5 answers

The cache will not validate the database because it contradicts the idea of ​​caching.
Instead, you can update or delete objects from the cache when their value in the database changes.

+6
source share

If the data can be changed in a database that is not controlled by your application, where you can implement your cache in write-through mode, then this data is probably not a good candidate for caching (provided that you can live with outdated data before until they are evicted).

+1
source share

The cache, of course, does not check the database. You have to do it yourself. You know how the tables in the database are related to each other and what tables you need to extract information for rendering the page. Do this (or not if you are satisfied with what you said mamcached).

0
source share

Is there a better way to cache things in which the cache will check inside the database to make sure that the data instead of relying on a timer that can cause synchronization problems?

This timer is not due to checking the database, but to free memory (pushing data from the cache).

From the Google engine (python) :

Memcache is usually used with the following pattern: An application receives a request from a user or expression. Checking the application whether the data needed to satisfy this request is in memcache. If the data is in memcache, the application uses that data. If there is no data in memcache, the application queries the data stores and stores the results in memcache for future requests. The below pseudo-code is a typical memcache request:

 def get_data(): data = memcache.get("key") if data is not None: return data else: data = self.query_for_data() memcache.add("key", data, 60) return data 

When updating the key (database), you will also need to update the memcache key.

0
source share

You might want to use redis. Although it is not semi-persistent, it will offer some storage mechanisms and has fast performance.

http://www.redis.io

0
source share

All Articles