I'm currently using Apc cache in a CakePHP application. I have thousands of listings that I want to cache as separate objects that can be read, updated, and overwritten independently. I then cache groups of listing_ids separately. There are some expensive location-based calculations that go into calculating the grouping of listing_ids that should be loaded (it's a maps application), so this list of listing_ids needs to be cached.

Listing data can also updated and saved through a dashboard. Caching works great until I save a specific listing, at which point all cached data is invalidated. When I go back to the map, and load a group of listings, those listings are no longer cached.

Some more specifics about implementation:

  • My cache configuration I'm using for both the list of listing_ids and the individual listings data:

Cache::config('Config1', array(

            'engine' => 'Apc', 
            'duration'=> 10000000, 
            'probability'=> 100, 
            'path' => CACHE, 
            'prefix' => 'cake_', 
            'lock' => false, 
            'serialize' => true, 
            'mask' => 0666,
    ));
  • To initialize the individual listings cache upon loading the map, I simply iterate over the listings returned from the database, caching each one with their listing_id appended to the end, like this:

    Cache::write('Listing-'.$id, $listing, 'Config1');

  • I have been able to ensure that the groups of listing_ids are being saved correctly. The line above is the same used when updating the listing in the dashboard as previously described.

My goal - update one specific listing in the cache while not touching the rest of the cached listings. Seems like a simple task, but I've spent several hours investigating and haven't been able to figure out the solution.

有帮助吗?

解决方案

Just rewrite the specific record like you are already doing

Cache::write('Listing-'.$id, $listing, 'Config1');
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top