How do HTTP caches store their requests ? Is there a commonly used protocol for caching requests or does each implementation have its own method for caching ?
EDIT : By this I mean how do the servers PHYSICALLY store cached requests, once the decision to cache has already been made.
I was looking through the functionality of some HTTP cache implementations such as polipo and found that they store (at least) part of their cache in the local file system but later found that nginx caches files/ file content (meaning there's a more efficient method for accessing cashed requests than storing them in the file system).
I was playing around with possible ideas and I tried to implement this method:
Hash request message -> store in a AVL -> access later using the hash value
This way it's simpler and reasonably effecient to search through the AVL to see whether the request has been serviced before. The AVL tree node has a pointer to the requests contents, this way they remain in main memory.
And I used this as the hash function:
static int hash( int size, request_t* bst_l) {
unsigned long int hashval;
int i = 0;
// Convert our string to an integer
while( hashval < ULONG_MAX && i < strlen( bst_l->MSG ) ) {
hashval = hashval << 8;
hashval += bst_l->MSG[ i ];
i++;
}
return hashval % size;
}
where size is the size of the AVL tree.
From this I expected a unique hash value for every unique message . Though I keep getting similar hash values for different requests. Is this because of the (hashval % size) line ?
Is the above method a good one in terms of scalability and efficiency ? and if so does the hash function match it properly ? Or is there a more common method for hashing requests ?