aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2010-05-04 17:07:07 +0000
committerMike Buland <eichlan@xagasoft.com>2010-05-04 17:07:07 +0000
commit51c5bfa4881b5def142092e10dd402fd40e2e712 (patch)
tree787ee6a56c14a51e92d8097bce87534ebbae4ec1
parent49af4dce0fdc569b623140ca5a711988281835d5 (diff)
downloadlibbu++-51c5bfa4881b5def142092e10dd402fd40e2e712.tar.gz
libbu++-51c5bfa4881b5def142092e10dd402fd40e2e712.tar.bz2
libbu++-51c5bfa4881b5def142092e10dd402fd40e2e712.tar.xz
libbu++-51c5bfa4881b5def142092e10dd402fd40e2e712.zip
Cache fixes?
-rw-r--r--src/cache.h24
-rw-r--r--src/cachecalc.h1
-rw-r--r--src/cachestore.h1
-rw-r--r--src/cachestorenids.h8
-rw-r--r--src/tests/cache.cpp13
5 files changed, 40 insertions, 7 deletions
diff --git a/src/cache.h b/src/cache.h
index 896aa71..dc5ab39 100644
--- a/src/cache.h
+++ b/src/cache.h
@@ -318,16 +318,26 @@ namespace Bu
318 printf("Shouldn't erase, references still exist!\n"); 318 printf("Shouldn't erase, references still exist!\n");
319 return; 319 return;
320 } 320 }
321
322 obtype *pObj = hEnt.get( cId ).pData;
323 pCalc->onDestroy( pObj, cId );
324 hEnt.erase( cId );
325
326 pStore->destroy( pObj, cId );
321 } 327 }
322 catch( Bu::HashException &e ) { 328 catch( Bu::HashException &e ) {
323 get( cId ); 329 pCalc->onDestroy( cId );
324 }
325
326 obtype *pObj = hEnt.get( cId ).pData;
327 pCalc->onDestroy( pObj, cId );
328 hEnt.erase( cId );
329 330
330 pStore->destroy( pObj, cId ); 331 if( hEnt.has( cId ) )
332 {
333 // The object was loaded by onDestroy
334 erase( cId );
335 }
336 else
337 {
338 pStore->destroy( cId );
339 }
340 }
331 } 341 }
332 342
333 typedef Bu::List<keytype> KeyList; 343 typedef Bu::List<keytype> KeyList;
diff --git a/src/cachecalc.h b/src/cachecalc.h
index d0729a9..e23e6fd 100644
--- a/src/cachecalc.h
+++ b/src/cachecalc.h
@@ -37,6 +37,7 @@ namespace Bu
37 virtual void onLoad( obtype *pSrc, const keytype &key )=0; 37 virtual void onLoad( obtype *pSrc, const keytype &key )=0;
38 virtual void onUnload( obtype *pSrc, const keytype &key )=0; 38 virtual void onUnload( obtype *pSrc, const keytype &key )=0;
39 virtual void onDestroy( obtype *pSrc, const keytype &key )=0; 39 virtual void onDestroy( obtype *pSrc, const keytype &key )=0;
40 virtual void onDestroy( const keytype &key )=0;
40 virtual bool shouldSync( obtype *pSrc, const keytype &key, 41 virtual bool shouldSync( obtype *pSrc, const keytype &key,
41 time_t tLastSync )=0; 42 time_t tLastSync )=0;
42 virtual void onTick() { }; 43 virtual void onTick() { };
diff --git a/src/cachestore.h b/src/cachestore.h
index 4e4435b..d35bc0a 100644
--- a/src/cachestore.h
+++ b/src/cachestore.h
@@ -34,6 +34,7 @@ namespace Bu
34 virtual void sync()=0; 34 virtual void sync()=0;
35 virtual void sync( obtype *pObj, const keytype &key )=0; 35 virtual void sync( obtype *pObj, const keytype &key )=0;
36 virtual void destroy( obtype *pObj, const keytype &key )=0; 36 virtual void destroy( obtype *pObj, const keytype &key )=0;
37 virtual void destroy( const keytype &key )=0;
37 virtual bool has( const keytype &key )=0; 38 virtual bool has( const keytype &key )=0;
38 virtual Bu::List<keytype> getKeys() { return Bu::List<keytype>(); } 39 virtual Bu::List<keytype> getKeys() { return Bu::List<keytype>(); }
39 virtual int getSize() { return -1; } 40 virtual int getSize() { return -1; }
diff --git a/src/cachestorenids.h b/src/cachestorenids.h
index f413bd0..293f521 100644
--- a/src/cachestorenids.h
+++ b/src/cachestorenids.h
@@ -125,6 +125,14 @@ namespace Bu
125 sync(); 125 sync();
126 } 126 }
127 127
128 virtual void destroy( const keytype &key )
129 {
130 int iStream = hId.get( key );
131 nStore.deleteStream( iStream );
132 hId.erase( key );
133 sync();
134 }
135
128 virtual bool has( const keytype &key ) 136 virtual bool has( const keytype &key )
129 { 137 {
130 return hId.has( key ); 138 return hId.has( key );
diff --git a/src/tests/cache.cpp b/src/tests/cache.cpp
index 3470ecb..7fe660a 100644
--- a/src/tests/cache.cpp
+++ b/src/tests/cache.cpp
@@ -160,6 +160,15 @@ public:
160 delete pObj; 160 delete pObj;
161 } 161 }
162 162
163 virtual void destroy( const long &key )
164 {
165 TRACE( pObj, key );
166 Bu::FString sDest;
167 sDest.format("bobcache/%d", key );
168 if( !access( sDest.getStr(), F_OK ) )
169 unlink( sDest.getStr() );
170 }
171
163private: 172private:
164 long cLastId; 173 long cLastId;
165}; 174};
@@ -187,6 +196,10 @@ public:
187 { 196 {
188 } 197 }
189 198
199 virtual void onDestroy( const long & )
200 {
201 }
202
190 virtual bool shouldSync( Bob *, const long &, time_t ) 203 virtual bool shouldSync( Bob *, const long &, time_t )
191 { 204 {
192 return false; 205 return false;