Optimization of persistent state storage in cookies
Optimization of persistent state storage in cookies
In my project I have two large datatables which save its state in cookies. Average size of data to store is about 1500-2000 bytes. Saving state of one table cause cookie expiration of another due to 4 KiB limit. In current implementation, old cookies are expired in order of creation time. I think that it is necessary to expire cookie of current table at first if exists.
Here is a path.
[code]
@@ -4517,6 +4517,7 @@
if ( iNewCookieLen+document.cookie.length+10 > 4096 ) /* Magic 10 for padding */
{
+ var equalCookieIdx = -1;
for ( var i=0, iLen=aCookies.length ; i= 0 )
+ {
+ var old = aOldCookies[equalCookieIdx];
+ document.cookie = old.name+"=; expires=Thu, 01-Jan-1970 00:00:01 GMT; path="+
+ aParts.join('/') + "/";
+ aOldCookies.splice(equalCookieIdx, 0);
}
// Make sure we delete the oldest ones first
[/code]
Here is a path.
[code]
@@ -4517,6 +4517,7 @@
if ( iNewCookieLen+document.cookie.length+10 > 4096 ) /* Magic 10 for padding */
{
+ var equalCookieIdx = -1;
for ( var i=0, iLen=aCookies.length ; i= 0 )
+ {
+ var old = aOldCookies[equalCookieIdx];
+ document.cookie = old.name+"=; expires=Thu, 01-Jan-1970 00:00:01 GMT; path="+
+ aParts.join('/') + "/";
+ aOldCookies.splice(equalCookieIdx, 0);
}
// Make sure we delete the oldest ones first
[/code]
This discussion has been closed.
Replies
Allan