From 88b3a5acf78aa9a2d73f2462e45988f5afb9d2c5 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Tue, 24 Feb 2009 01:23:11 +0000 Subject: Woot, the cache system now supports intellegent sync'ing. It will ask the cache about each object that it has and weather or not to sync it. This will probably be made optional in the future. --- src/cache.h | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) (limited to 'src/cache.h') diff --git a/src/cache.h b/src/cache.h index 036ceb4..4ae1aa8 100644 --- a/src/cache.h +++ b/src/cache.h @@ -143,6 +143,7 @@ namespace Bu { obtype *pData; int iRefs; + time_t tLastSync; } CacheEntry; typedef Bu::Hash CidHash; @@ -184,7 +185,7 @@ namespace Bu Ptr insert( obtype *pData ) { TRACE( pData ); - CacheEntry e = {pData, 0}; + CacheEntry e = {pData, 0, 0}; keytype k = pStore->create( pData ); hEnt.insert( k, e ); @@ -205,7 +206,7 @@ namespace Bu return Ptr( this, hEnt.get( cId ).pData, cId ); } catch( Bu::HashException &e ) { - CacheEntry e = {pStore->load( cId ), 0}; + CacheEntry e = {pStore->load( cId ), 0, time( NULL )}; pCalc->onLoad( e.pData, cId ); hEnt.insert( cId, e ); return Ptr( this, e.pData, cId ); @@ -285,11 +286,19 @@ namespace Bu { if( i.getValue().iRefs == 0 ) { - pStore->sync( - i.getValue().pData, - i.getKey() - ); - iSynced++; + if( pCalc->shouldSync( + i.getValue().pData, + i.getKey(), + i.getValue().tLastSync + ) ) + { + pStore->sync( + i.getValue().pData, + i.getKey() + ); + iSynced++; + i.getValue().tLastSync = time( NULL ); + } } } if( iSynced > 0 ) @@ -319,7 +328,7 @@ namespace Bu return hEnt.get( cId ).pData; } catch( Bu::HashException &e ) { - CacheEntry e = {pStore->load( cId ), 0}; + CacheEntry e = {pStore->load( cId ), 0, time( NULL )}; pCalc->onLoad( e.pData, cId ); hEnt.insert( cId, e ); return e.pData; -- cgit v1.2.3