캐시 해시에 키를 생성하기위한 알고리즘으로 인해 특정 파일의 캐싱을 방지하는 a bug in Firefox (새 베타 및 지뢰밭 릴리스 포함)이 있습니다. Here is a link to the source code of the function.firefox 캐시 해시 키 생성 알고리즘 버그
내 사이트의 파일을 모두 캐시 할 수있게하려는 것입니다. 그러나, 왜 자신의 해시 함수가 고유 한 URL에 대한 고유 키를 만들지 못하는지 이해할 수 없습니다. 누군가 이 psuedo-code 또는 java로 표시 될 수 있기를 바랍니다.
개발자가이 버그가 해결 될 때까지 고유 URL을 유지할 수있는 유틸리티를 만드는 것이 좋습니다.
편집 : 그러나, 나는이 캐시 혼입를 확인하기 위해 유틸리티를 만들 수있는 더 단계별로 도움을 필요로, 매우 도움이 답변이왔다. 파이어 폭스가 만들고있는 키를 재현 할 수있는 자바 코드를 얻는 것이 좋다. 그러므로,이 질문에 현상금을 여는 것.
EDIT 2 여기 (processing로 작성된) 부분적으로 작동하는 자바 포트이다. 하단의 테스트에 유의하십시오. 처음 세 개는 예상대로 작동하지만 다른 개는 작동하지 않습니다. 나는 서명/서명되지 않은 ints에 관한 무언가를 의심합니다. 제안?
난 그냥 버그 질라 항목을 읽는 이해하는 것과//
// the bad collision function
// http://mxr.mozilla.org/mozilla/source/netwerk/cache/src/nsDiskCacheDevice.cpp#240
//
//248 PLDHashNumber
//249 nsDiskCache::Hash(const char * key)
//250 {
//251 PLDHashNumber h = 0;
//252 for (const PRUint8* s = (PRUint8*) key; *s != '\0'; ++s)
//253 h = PR_ROTATE_LEFT32(h, 4)^*s;
//254 return (h == 0 ? ULONG_MAX : h);
//255 }
//
// a java port...
//
String getHash(String url)
{
//get the char array for the url string
char[] cs = getCharArray(url);
int h = 0;
//for (const PRUint8* s = (PRUint8*) key; *s != '\0'; ++s)
for (int i=0; i < cs.length; i++)
{ h = PR_ROTATE_LEFT32(h, 4)^cs[i];
}
//looks like the examples above return something in hex.
//if we get matching ints, that is ok by me.
//but for fun, lets try to hex the return vals?
String hexVal = hex(h);
return hexVal;
}
char[] getCharArray(String s)
{
char[] cs = new char[s.length()];
for (int i=0; i<s.length(); i++)
{
char c = s.charAt(i);
cs[i] = c;
}
return cs;
}
//
// how to PR_ROTATE_LEFT32
//
//110 /*
//111 ** Macros for rotate left and right. The argument 'a' must be an unsigned
//112 ** 32-bit integer type such as PRUint32.
//113 **
//114 ** There is no rotate operation in the C Language, so the construct
//115 ** (a << 4) | (a >> 28) is frequently used instead. Most compilers convert
//116 ** this to a rotate instruction, but MSVC doesn't without a little help.
//117 ** To get MSVC to generate a rotate instruction, we have to use the _rotl
//118 ** or _rotr intrinsic and use a pragma to make it inline.
//119 **
//120 ** Note: MSVC in VS2005 will do an inline rotate instruction on the above
//121 ** construct.
//122 */
//...
//128 #define PR_ROTATE_LEFT32(a, bits) _rotl(a, bits)
//return an int (32 bit). what do we do with the 'bits' parameter? ignore?
int PR_ROTATE_LEFT32(int a, int bits)
{ return (a << 4) | (a >> (32-bits));
}
//
// examples of some colliding hashes
// https://bugzilla.mozilla.org/show_bug.cgi?id=290032#c5
//
//$ ./hashit "ABA/xxx.aba"
//8ffac222
//$ ./hashit "XyZ/xxx.xYz"
//8ffac222
//$ ./hashit "CSS/xxx.css"
//8ffac222
//$ ./hashit "JPG/xxx.jpg"
//8ffac222
//$ ./hashit modules_newsfeeds/MenuBar/MenuBar.css
//15c23729
//$ ./hashit modules_newsfeeds/ListBar/ListBar.css
//15c23729
//$ ./hashit modules_newsfeeds/MenuBar/MenuBar.js
//a15c23e5
//$ ./hashit modules_newsfeeds/ListBar/ListBar.js
//a15c23e5
//
// our attempt at porting this algorithm to java...
//
void setup()
{
String a = "ABA/xxx.aba";
String b = "CSS/xxx.css";
String c = "CSS/xxx.css";
String d = "JPG/xxx.jpg";
println(getHash(a)); //yes 8ffac222
println(getHash(b)); //yes 8ffac222
println(getHash(c)); //yes 8ffac222
println(getHash(d)); //no [??] FFFFFF98, not 8ffac222
println("-----");
String e = "modules_newsfeeds/MenuBar/MenuBar.css";
String f = "modules_newsfeeds/ListBar/ListBar.css";
println(getHash(e)); //no [??] FFFFFF8C, not 15c23729
println(getHash(f)); //no [??] FFFFFF8C, not 15c23729
println("-----");
String g = "modules_newsfeeds/MenuBar/MenuBar.js";
String h = "modules_newsfeeds/ListBar/ListBar.js";
println(getHash(g)); //yes [??] FFFFFF8C, not a15c23e5
println(getHash(h)); //yes [??] FFFFFF8C, not a15c23e5
}
솔직히 나는 당신이 너무 많이 걱정하고 있다고 생각합니다. 어떤 종류의 문제가 발생 했습니까? 아니면이 모든 조기 최적화입니까? –
에 문제가 발생했습니다. : -/ – jedierikb
문제에 대한 추가 설명 : 수천 개 이상의 파일을 올바르게 캐시하는 전략을 수립해야합니다. 지금은 그렇지 않습니다. 모든 파일 이름을 사전 처리하여 캐시 가능함을 확인합니다. – jedierikb