From b4f8ebcb496ca231fa737307a0f9757d01e37c7b Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Sat, 1 May 2010 19:20:21 +0000 Subject: Cache fixes. --- src/cache.h | 33 +++++++++++++-------------------- src/cachecalc.h | 1 + src/cachestorenids.h | 1 + src/tests/cache.cpp | 10 ++++++++++ 4 files changed, 25 insertions(+), 20 deletions(-) (limited to 'src') diff --git a/src/cache.h b/src/cache.h index 1753407..896aa71 100644 --- a/src/cache.h +++ b/src/cache.h @@ -112,11 +112,6 @@ namespace Bu return pData != NULL; } - operator bool() const - { - return isBound() && isValid(); - } - const keytype &getKey() const { return kId; @@ -297,7 +292,7 @@ namespace Bu try { if( hEnt.get( cId ).iRefs > 0 ) { - printf("Shouldn't delete, references still exist!\n"); + printf("Shouldn't unload, references still exist!\n"); return; } } @@ -317,24 +312,22 @@ namespace Bu void erase( const keytype &cId ) { TRACE( cId ); - if( hEnt.has( cId ) ) - { - try { - if( hEnt.get( cId ).iRefs > 0 ) - { - printf("Shouldn't delete, references still exist!\n"); - return; - } - } - catch( Bu::HashException &e ) { - get( cId ); + try { + if( hEnt.get( cId ).iRefs > 0 ) + { + printf("Shouldn't erase, references still exist!\n"); + return; } - - pCalc->onUnload( hEnt.get( cId ).pData, cId ); - pStore->destroy( hEnt.get( cId ).pData, cId ); + } + catch( Bu::HashException &e ) { + get( cId ); } + obtype *pObj = hEnt.get( cId ).pData; + pCalc->onDestroy( pObj, cId ); hEnt.erase( cId ); + + pStore->destroy( pObj, cId ); } typedef Bu::List KeyList; diff --git a/src/cachecalc.h b/src/cachecalc.h index c9968dc..d0729a9 100644 --- a/src/cachecalc.h +++ b/src/cachecalc.h @@ -36,6 +36,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 bool shouldSync( obtype *pSrc, const keytype &key, time_t tLastSync )=0; virtual void onTick() { }; diff --git a/src/cachestorenids.h b/src/cachestorenids.h index 54129b0..f413bd0 100644 --- a/src/cachestorenids.h +++ b/src/cachestorenids.h @@ -122,6 +122,7 @@ namespace Bu nStore.deleteStream( iStream ); hId.erase( key ); delete pObj; + sync(); } virtual bool has( const keytype &key ) diff --git a/src/tests/cache.cpp b/src/tests/cache.cpp index 97aba4a..3470ecb 100644 --- a/src/tests/cache.cpp +++ b/src/tests/cache.cpp @@ -41,6 +41,12 @@ public: TRACE( i ); iInt = i; } + + long getKey() const + { + TRACE( i ); + return iInt; + } int getInt() { @@ -177,6 +183,10 @@ public: { } + virtual void onDestroy( Bob *, const long & ) + { + } + virtual bool shouldSync( Bob *, const long &, time_t ) { return false; -- cgit v1.2.3