Skip to content
This repository was archived by the owner on Jul 3, 2024. It is now read-only.

Commit 382a237

Browse files
tweaks to the caching setup:
* revised clearBrowserCache for IE userData and localStorage * prefixed all cached items in localStorage with eCSStender- so we can remove them individually * caching the eCSStender version number * adjusted the cache-reading mechanism to check against current eCSStender version number before reading. If version numbers don't match, it doesn't read the cache, it only wipes it.
1 parent 15828ca commit 382a237

File tree

1 file changed

+50
-25
lines changed

1 file changed

+50
-25
lines changed

src/eCSStender.js

Lines changed: 50 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1352,14 +1352,31 @@ License: MIT License (see homepage)
13521352
__cache_object = WINDOW.localStorage;
13531353
clearBrowserCache = function()
13541354
{
1355-
__cache_object.clear();
1355+
// cherry-pick only our own items in the cache
1356+
for ( var key in __cache_object )
1357+
{
1358+
if ( key.indexOf( ECSSTENDER ) === 0 )
1359+
{
1360+
delete( __cache_object[key] );
1361+
}
1362+
}
13561363
};
13571364
readFromBrowserCache = function( cache, key )
13581365
{
1366+
// make sure our cached objects are prefixed
1367+
if ( cache != ECSSTENDER )
1368+
{
1369+
cache = ECSSTENDER + HYPHEN + cache;
1370+
}
13591371
return __cache_object.getItem( cache + HYPHEN + key );
13601372
};
13611373
writeToBrowserCache = function( cache, key, value )
13621374
{
1375+
// make sure our cached objects are prefixed
1376+
if ( cache != ECSSTENDER )
1377+
{
1378+
cache = ECSSTENDER + HYPHEN + cache;
1379+
}
13631380
__cache_object.setItem( cache + HYPHEN + key, value );
13641381
};
13651382
}
@@ -1406,38 +1423,45 @@ License: MIT License (see homepage)
14061423
{
14071424
if ( __no_cache || __local ){ return; }
14081425
enableCache();
1409-
var cache_group, item, count;
1410-
for ( cache_group in __local_cache )
1426+
var cache_group, item, count,
1427+
version = 'version',
1428+
cache_version = readFromBrowserCache( ECSSTENDER, version );
1429+
// only use the cache if it was created from the same version of eCSStender
1430+
// this allows us to tweak the cache going forward
1431+
if ( cache_version == eCSStender[version] )
14111432
{
1412-
if ( ! isInheritedProperty( __local_cache, cache_group ) &&
1413-
defined( cache_group ) )
1433+
for ( cache_group in __local_cache )
14141434
{
1415-
count = readFromBrowserCache( ECSSTENDER, cache_group + COUNT );
1416-
if ( defined( count ) )
1435+
if ( ! isInheritedProperty( __local_cache, cache_group ) &&
1436+
defined( cache_group ) )
14171437
{
1418-
if ( cache_group == EXTENSION )
1438+
count = readFromBrowserCache( ECSSTENDER, cache_group + COUNT );
1439+
if ( defined( count ) )
14191440
{
1420-
__t_count = count;
1421-
if ( count < 1 ){ eCSStender.cache = FALSE; }
1422-
}
1423-
while ( count >= 0 )
1424-
{
1425-
item = readFromBrowserCache( cache_group, count );
1426-
if ( item != NULL )
1441+
if ( cache_group == EXTENSION )
14271442
{
1428-
if ( cache_group == EXTENSION )
1429-
{
1430-
__local_cache[cache_group][EXTENSION+count] = item;
1431-
}
1432-
else
1443+
__t_count = count;
1444+
if ( count < 1 ){ eCSStender.cache = FALSE; }
1445+
}
1446+
while ( count >= 0 )
1447+
{
1448+
item = readFromBrowserCache( cache_group, count );
1449+
if ( item != NULL )
14331450
{
1434-
item = item.split(PIPES);
1435-
if ( item[1] == 'true' ){ item[1] = TRUE; }
1436-
if ( item[1] == 'false' ){ item[1] = FALSE; }
1437-
__local_cache[cache_group][item[0]] = item[1];
1451+
if ( cache_group == EXTENSION )
1452+
{
1453+
__local_cache[cache_group][EXTENSION+count] = item;
1454+
}
1455+
else
1456+
{
1457+
item = item.split(PIPES);
1458+
if ( item[1] == 'true' ){ item[1] = TRUE; }
1459+
if ( item[1] == 'false' ){ item[1] = FALSE; }
1460+
__local_cache[cache_group][item[0]] = item[1];
1461+
}
14381462
}
1463+
count--;
14391464
}
1440-
count--;
14411465
}
14421466
}
14431467
}
@@ -1475,6 +1499,7 @@ License: MIT License (see homepage)
14751499
writeToBrowserCache( ECSSTENDER, cache_group + COUNT, count );
14761500
}
14771501
}
1502+
writeToBrowserCache( ECSSTENDER, 'version', eCSStender.version );
14781503
__cached_out = TRUE;
14791504
}
14801505
function styleObjToString( obj )

0 commit comments

Comments
 (0)