File tree Expand file tree Collapse file tree 2 files changed +32
-0
lines changed Expand file tree Collapse file tree 2 files changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -209,7 +209,11 @@ function clear($check) {
209
209
$ now = time ();
210
210
$ threshold = $ now - $ this ->settings ['duration ' ];
211
211
}
212
+ $ prefixLength = strlen ($ this ->settings ['prefix ' ]);
212
213
while (($ entry = $ dir ->read ()) !== false ) {
214
+ if (substr ($ entry , 0 , $ prefixLength ) !== $ this ->settings ['prefix ' ]) {
215
+ continue ;
216
+ }
213
217
if ($ this ->_setKey ($ entry ) === false ) {
214
218
continue ;
215
219
}
Original file line number Diff line number Diff line change @@ -273,6 +273,34 @@ function testClear() {
273
273
Cache::config ('default ' , array ('engine ' => 'File ' , 'path ' => CACHE ));
274
274
}
275
275
276
+ /**
277
+ * test that clear() doesn't wipe files not in the current engine's prefix.
278
+ *
279
+ * @return void
280
+ */
281
+ function testClearWithPrefixes () {
282
+ $ FileOne =& new FileEngine ();
283
+ $ FileOne ->init (array (
284
+ 'prefix ' => 'prefix_one_ ' ,
285
+ 'duration ' => DAY
286
+ ));
287
+ $ FileTwo =& new FileEngine ();
288
+ $ FileTwo ->init (array (
289
+ 'prefix ' => 'prefix_two_ ' ,
290
+ 'duration ' => DAY
291
+ ));
292
+
293
+ $ data1 = $ data2 = $ expected = 'content to cache ' ;
294
+ $ FileOne ->write ('key_one ' , $ data1 , DAY );
295
+ $ FileTwo ->write ('key_two ' , $ data2 , DAY );
296
+
297
+ $ this ->assertEqual ($ FileOne ->read ('key_one ' ), $ expected );
298
+ $ this ->assertEqual ($ FileTwo ->read ('key_two ' ), $ expected );
299
+
300
+ $ FileOne ->clear (false );
301
+ $ this ->assertEqual ($ FileTwo ->read ('key_two ' ), $ expected , 'secondary config was cleared by accident. ' );
302
+ }
303
+
276
304
/**
277
305
* testKeyPath method
278
306
*
You can’t perform that action at this time.
0 commit comments