We using memcached + PHP and have a single server environment. We are using dirty and persist(commit) method to update the data to DB. The problem is we found the record duplicated twice in DB occasionally. The code to update dirty are like:
$cache->get('dirty');//the dirty hold all the sql statment that need to be updated.
$updatedDirty = ....//add new data to dirty
$cache->set($updatedDirty, 'dirty', 3600);//lets say cache it for one hour.
Every 20 second, the server will run following script to persist(commit) the data from dirty to DB:
$toBeUpdated = $cache->get('dirty');
$cache->delete('dirty',0);
commit($toBeUpdated);
the dirty is copied by value to $toBeUpdated. Then the dirty cache have deleted. This is not the case that the is record duplicuted before $cache->get('dirty') or during $cache->get('dirty') since the duplication is occur in two different commit batch. Anyone have experienced any other scenario that will cause the record duplication problem? Thank you so much for your help!