@@ -34,7 +34,7 @@ public function __construct($directory, $defaultLifetime = null)
34
34
throw new InvalidArgumentException (sprintf ('Cache directory is not writable (%s) ' , $ directory ));
35
35
}
36
36
// On Windows the whole path is limited to 258 chars
37
- if ('\\' === DIRECTORY_SEPARATOR && strlen ($ dir ) > 190 ) {
37
+ if ('\\' === DIRECTORY_SEPARATOR && strlen ($ dir ) > 234 ) {
38
38
throw new InvalidArgumentException (sprintf ('Cache directory too long (%s) ' , $ directory ));
39
39
}
40
40
@@ -62,10 +62,13 @@ protected function doFetch(array $ids)
62
62
@unlink ($ file );
63
63
}
64
64
} else {
65
+ $ i = rawurldecode (rtrim (fgets ($ h )));
65
66
$ value = stream_get_contents ($ h );
66
67
flock ($ h , LOCK_UN );
67
68
fclose ($ h );
68
- $ values [$ id ] = unserialize ($ value );
69
+ if ($ i === $ id ) {
70
+ $ values [$ id ] = unserialize ($ value );
71
+ }
69
72
}
70
73
}
71
74
@@ -125,7 +128,7 @@ protected function doSave(array $values, $lifetime)
125
128
if (!file_exists ($ dir )) {
126
129
@mkdir ($ dir , 0777 , true );
127
130
}
128
- $ value = $ expiresAt ."\n" .serialize ($ value );
131
+ $ value = $ expiresAt ."\n" .rawurlencode ( $ id ). "\n" . serialize ($ value );
129
132
if (false !== @file_put_contents ($ file , $ value , LOCK_EX )) {
130
133
@touch ($ file , $ expiresAt );
131
134
} else {
@@ -138,8 +141,8 @@ protected function doSave(array $values, $lifetime)
138
141
139
142
private function getFile ($ id )
140
143
{
141
- $ hash = hash ( ' sha256 ' , $ id );
144
+ $ hash = str_replace ( ' / ' , ' - ' , base64_encode ( md5 ( $ id, true )) );
142
145
143
- return $ this ->directory .$ hash [0 ].DIRECTORY_SEPARATOR .$ hash [1 ].DIRECTORY_SEPARATOR .$ hash ;
146
+ return $ this ->directory .$ hash [0 ].DIRECTORY_SEPARATOR .$ hash [1 ].DIRECTORY_SEPARATOR .substr ( $ hash, 2 , - 2 ) ;
144
147
}
145
148
}
0 commit comments