laravel/framework — pull request #1906 by karptonite (2013-07-19 05:46:49+00:00)
Title: Safely flush empty section, and avoid returning stale data from sections

This patch should solve two issues.

First, it allows flush to be called on a section even if the section does not exist. (see issue #1885)

Second, it will solve a potential bug that would allow stale data to be served from a section. This second bug would come about as follows: Memcached does not guarantee to keep all records. Say a section has been used, and flushed, frequently, before the Memcached record corresponding to the SectionId is lost for some reason. If the ID had originally started at, say, 1000, and it had been flushed thousands of times, then it is likely that any new sectionId (a random number 1-10000) would collide with one of the old sectionIds. The caches stored in that old section would then be returned, with the stale data. Changing the sectionId from a random integer to a uniqid will prevent the return of stale data in this way.

There were no test cases for Cache Sections, and I don't have any caching systems installed on my local system to test my changes, so this is not fully tested, but the change is quite simple.