From 6f3b85c5af1855e1695885fb28220c34f6a0673f Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Mon, 1 Dec 2008 23:10:44 +0000 Subject: Wow, that's a lot of changes. You can use anything as a key now, as long as it can be hashed. And we're about to test actually loading and saving persistant cache items. Fun. --- src/tests/cache.cpp | 66 +++++++++++++++++++++++++++++++++++------------------ 1 file changed, 44 insertions(+), 22 deletions(-) (limited to 'src/tests') diff --git a/src/tests/cache.cpp b/src/tests/cache.cpp index 55ec5be..1cc008a 100644 --- a/src/tests/cache.cpp +++ b/src/tests/cache.cpp @@ -1,4 +1,7 @@ #include +#include +#include +#include #include "bu/cache.h" @@ -35,55 +38,74 @@ public: int iInt; }; -class BobHandler : public Bu::CacheHandler +class BobStore : public Bu::CacheStore { public: - BobHandler() : + BobStore() : cLastId( 0 ) { + TRACE(); } - ~BobHandler() - { - } - - virtual Bu::CPtr load() + ~BobStore() { + TRACE(); } - virtual void unload( Bu::CPtr pObj ) + virtual Bob *load( const long &key ) { + TRACE(); + return NULL; } - virtual Bu::CPtr create() + virtual void unload( Bob *pObj ) { + TRACE(); + delete pObj; } - virtual Bu::CPtr create( Bob &rSrc ) + virtual long create( Bob *rSrc ) { + TRACE(); + return ++cLastId; } - virtual void destroy( Bu::CPtr pObj ) + virtual void destroy( Bob *pObj, const long &key ) { + TRACE(); + delete pObj; } private: - Bu::Cache::cid_t cLastId; + long cLastId; }; -int main() +int main( int argc, char *argv[] ) { - typedef Bu::Cache BobCache; - typedef Bu::CPtr BobPtr; + TRACE(); + if( argc < 3 ) + { + printf("Try: %s [icufd] []\n\n", argv[0] ); + return 0; + } + + switch( argv[1][0] ) + { + case 'i': + mkdir("bobcache", 0755 ); + printf("Initialized cache: %s\n", strerror( errno ) ); + return 0; + + case 'c': + typedef Bu::Cache BobCache; + typedef BobCache::Ptr BobPtr; - BobCache bobCache; + BobCache cBob; - BobPtr pB1 = bobCache.insert( new Bob() ); - (*pB1).setInt( 44 ); - printf("RefCnt = %d\n", bobCache.getRefCnt( 0 ) ); + cBob.appendStore( new BobStore() ); + + return 0; + } - BobPtr pB2 = bobCache.get( 0 ); - printf("RefCnt = %d\n", bobCache.getRefCnt( 0 ) ); - printf("Int = %d\n", pB2->getInt() ); } -- cgit v1.2.3