aboutsummaryrefslogtreecommitdiff
path: root/src/cache.h
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2009-02-24 01:23:11 +0000
committerMike Buland <eichlan@xagasoft.com>2009-02-24 01:23:11 +0000
commit88b3a5acf78aa9a2d73f2462e45988f5afb9d2c5 (patch)
tree8544b797ed76f9ffe79d4ccce6f9b4ffcf69889f /src/cache.h
parentef2935347099967cc7092fa7f472d91d51571468 (diff)
downloadlibbu++-88b3a5acf78aa9a2d73f2462e45988f5afb9d2c5.tar.gz
libbu++-88b3a5acf78aa9a2d73f2462e45988f5afb9d2c5.tar.bz2
libbu++-88b3a5acf78aa9a2d73f2462e45988f5afb9d2c5.tar.xz
libbu++-88b3a5acf78aa9a2d73f2462e45988f5afb9d2c5.zip
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.
Diffstat (limited to '')
-rw-r--r--src/cache.h25
1 files changed, 17 insertions, 8 deletions
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
143 { 143 {
144 obtype *pData; 144 obtype *pData;
145 int iRefs; 145 int iRefs;
146 time_t tLastSync;
146 } CacheEntry; 147 } CacheEntry;
147 148
148 typedef Bu::Hash<keytype, CacheEntry> CidHash; 149 typedef Bu::Hash<keytype, CacheEntry> CidHash;
@@ -184,7 +185,7 @@ namespace Bu
184 Ptr insert( obtype *pData ) 185 Ptr insert( obtype *pData )
185 { 186 {
186 TRACE( pData ); 187 TRACE( pData );
187 CacheEntry e = {pData, 0}; 188 CacheEntry e = {pData, 0, 0};
188 keytype k = pStore->create( pData ); 189 keytype k = pStore->create( pData );
189 hEnt.insert( k, e ); 190 hEnt.insert( k, e );
190 191
@@ -205,7 +206,7 @@ namespace Bu
205 return Ptr( this, hEnt.get( cId ).pData, cId ); 206 return Ptr( this, hEnt.get( cId ).pData, cId );
206 } 207 }
207 catch( Bu::HashException &e ) { 208 catch( Bu::HashException &e ) {
208 CacheEntry e = {pStore->load( cId ), 0}; 209 CacheEntry e = {pStore->load( cId ), 0, time( NULL )};
209 pCalc->onLoad( e.pData, cId ); 210 pCalc->onLoad( e.pData, cId );
210 hEnt.insert( cId, e ); 211 hEnt.insert( cId, e );
211 return Ptr( this, e.pData, cId ); 212 return Ptr( this, e.pData, cId );
@@ -285,11 +286,19 @@ namespace Bu
285 { 286 {
286 if( i.getValue().iRefs == 0 ) 287 if( i.getValue().iRefs == 0 )
287 { 288 {
288 pStore->sync( 289 if( pCalc->shouldSync(
289 i.getValue().pData, 290 i.getValue().pData,
290 i.getKey() 291 i.getKey(),
291 ); 292 i.getValue().tLastSync
292 iSynced++; 293 ) )
294 {
295 pStore->sync(
296 i.getValue().pData,
297 i.getKey()
298 );
299 iSynced++;
300 i.getValue().tLastSync = time( NULL );
301 }
293 } 302 }
294 } 303 }
295 if( iSynced > 0 ) 304 if( iSynced > 0 )
@@ -319,7 +328,7 @@ namespace Bu
319 return hEnt.get( cId ).pData; 328 return hEnt.get( cId ).pData;
320 } 329 }
321 catch( Bu::HashException &e ) { 330 catch( Bu::HashException &e ) {
322 CacheEntry e = {pStore->load( cId ), 0}; 331 CacheEntry e = {pStore->load( cId ), 0, time( NULL )};
323 pCalc->onLoad( e.pData, cId ); 332 pCalc->onLoad( e.pData, cId );
324 hEnt.insert( cId, e ); 333 hEnt.insert( cId, e );
325 return e.pData; 334 return e.pData;