From 51c5bfa4881b5def142092e10dd402fd40e2e712 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Tue, 4 May 2010 17:07:07 +0000 Subject: Cache fixes? --- src/cache.h | 24 +++++++++++++++++------- src/cachecalc.h | 1 + src/cachestore.h | 1 + src/cachestorenids.h | 8 ++++++++ src/tests/cache.cpp | 13 +++++++++++++ 5 files changed, 40 insertions(+), 7 deletions(-) (limited to 'src') 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 printf("Shouldn't erase, references still exist!\n"); return; } + + obtype *pObj = hEnt.get( cId ).pData; + pCalc->onDestroy( pObj, cId ); + hEnt.erase( cId ); + + pStore->destroy( pObj, cId ); } catch( Bu::HashException &e ) { - get( cId ); - } - - obtype *pObj = hEnt.get( cId ).pData; - pCalc->onDestroy( pObj, cId ); - hEnt.erase( cId ); + pCalc->onDestroy( cId ); - pStore->destroy( pObj, cId ); + if( hEnt.has( cId ) ) + { + // The object was loaded by onDestroy + erase( cId ); + } + else + { + pStore->destroy( cId ); + } + } } typedef Bu::List 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 virtual void onLoad( obtype *pSrc, const keytype &key )=0; virtual void onUnload( obtype *pSrc, const keytype &key )=0; virtual void onDestroy( obtype *pSrc, const keytype &key )=0; + virtual void onDestroy( const keytype &key )=0; virtual bool shouldSync( obtype *pSrc, const keytype &key, time_t tLastSync )=0; 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 virtual void sync()=0; virtual void sync( obtype *pObj, const keytype &key )=0; virtual void destroy( obtype *pObj, const keytype &key )=0; + virtual void destroy( const keytype &key )=0; virtual bool has( const keytype &key )=0; virtual Bu::List getKeys() { return Bu::List(); } 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 sync(); } + virtual void destroy( const keytype &key ) + { + int iStream = hId.get( key ); + nStore.deleteStream( iStream ); + hId.erase( key ); + sync(); + } + virtual bool has( const keytype &key ) { 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: delete pObj; } + virtual void destroy( const long &key ) + { + TRACE( pObj, key ); + Bu::FString sDest; + sDest.format("bobcache/%d", key ); + if( !access( sDest.getStr(), F_OK ) ) + unlink( sDest.getStr() ); + } + private: long cLastId; }; @@ -187,6 +196,10 @@ public: { } + virtual void onDestroy( const long & ) + { + } + virtual bool shouldSync( Bob *, const long &, time_t ) { return false; -- cgit v1.2.3