a bug in Firefox (यहां तक कि नए बीटा और माइनफील्ड रिलीज़ में भी) है जो कुछ फ़ाइलों की कैशिंग को रोकता है क्योंकि उनके कैश हैश में कुंजी बनाने के लिए एल्गोरिदम की वजह से। Here is a link to the source code of the function।फ़ायरफ़ॉक्स कैश हैश कुंजी पीढ़ी एल्गोरिदम बग
मैं यह सुनिश्चित करना चाहता हूं कि मेरी सभी साइट की फ़ाइलों को कैश किया जा सके। हालांकि, मुझे समझ में नहीं आता कि क्यों उनके हैशिंग फ़ंक्शन विशिष्ट यूआरएल के लिए अद्वितीय कुंजी बनाने में विफल रहता है। मुझे आशा है कि कोई भी psuedo-code या जावा में mal फ़ंक्शन का वर्णन कर सकता है।
डेवलपर्स के लिए यह बग ठीक होने तक अद्वितीय यूआरएल सुनिश्चित करने के लिए उपयोगिता बनाना अच्छा होगा।
संपादित करें: वहाँ कुछ बहुत ही उपयोगी जवाब दिया गया है, फिर भी, मैं और कदम-दर-कदम मदद इन कैश उलझनों से जांच करने के लिए एक उपयोगिता बनाना होगा। कुछ जावा कोड प्राप्त करना बहुत अच्छा होगा जो फ़ायरफ़ॉक्स बनाने वाली कुंजियों को पुन: उत्पन्न कर सकता है। इसलिए, इस सवाल पर एक बक्षीस खोलना।
संपादित करें 2: यहाँ एक आंशिक रूप से काम कर रहे जावा बंदरगाह (लिखित processing का उपयोग) है। नीचे परीक्षणों पर ध्यान दें; उम्मीद के अनुसार पहले तीन काम, लेकिन दूसरों को नहीं। मुझे हस्ताक्षरित/हस्ताक्षरित इनट्स के बारे में कुछ संदेह है। सुझाव?
//
// 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