aboutsummaryrefslogtreecommitdiff
path: root/src/cache.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/cache.h')
-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;