Created
August 1, 2012 03:15
-
-
Save jayrgee/3223296 to your computer and use it in GitHub Desktop.
JS implmentation of RavenDB NoCache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// JS implmentation of Raven.Client.Silverlight.Connection.RavenUrlExtensions.NoCache | |
//public static string NoCache(this string url) | |
//{ | |
// return (url.Contains("?")) | |
// ? url + "&noCache=" + Guid.NewGuid().GetHashCode() | |
// : url + "?noCache=" + Guid.NewGuid().GetHashCode(); | |
//} | |
// http://note19.com/2007/05/27/javascript-guid-generator/ | |
function S4() { | |
return (((1+Math.random())*0x10000)|0).toString(16).substring(1); | |
} | |
function guid() { | |
return (S4()+S4()+"-"+S4()+"-"+S4()+"-"+S4()+"-"+S4()+S4()+S4()); | |
} | |
// http://werxltd.com/wp/2010/05/13/javascript-implementation-of-javas-string-hashcode-method/ | |
String.prototype.hashCode = function(){ | |
var hash = 0; | |
if (this.length === 0) return hash; | |
for (i = 0; i < this.length; i++) { | |
char = this.charCodeAt(i); | |
hash = ((hash<<5)-hash)+char; | |
hash = hash & hash; // Convert to 32bit integer | |
} | |
return hash; | |
}; | |
console.log(guid().hashCode()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment