From 679d9fef2673eea18fe5d9c85df2b10b09a8a250 Mon Sep 17 00:00:00 2001 From: eilers Date: Sun, 29 Aug 2004 12:50:18 +0000 Subject: Added lookahead caching for addressbook (SQL-only) for speed improvement. --- (limited to 'libopie2/opiepim/core/opimaccesstemplate.h') diff --git a/libopie2/opiepim/core/opimaccesstemplate.h b/libopie2/opiepim/core/opimaccesstemplate.h index 55d600a..6f01b46 100644 --- a/libopie2/opiepim/core/opimaccesstemplate.h +++ b/libopie2/opiepim/core/opimaccesstemplate.h @@ -35,7 +35,6 @@ #include #include -#include #include #include @@ -128,6 +127,7 @@ public: virtual T find( int uid, const QArray&, uint current, typename OTemplateBase::CacheDirection dir = OTemplateBase::Forward )const; + /* invalidate cache here */ /** * clears the backend and invalidates the backend @@ -139,13 +139,15 @@ public: * @param t The item to add. * @return true if added successfully. */ - virtual bool add( const T& t ) ; + virtual bool add( const T& t ) ; + bool add( const OPimRecord& ); - // Needed for real generic access (eilers) - // Info: Take this if you are working with OPimRecord, which is a generic base class, and - // you need to add it into any database, you cannot generate a reference to - // it and casting may be not approriate, too. - // But take care that the accessing database is compatible to the real type of OPimRecord !! + /** + * Add an Opie PimRecord. + * Info: Take this if you are working with OPimRecords and you need to add it into any database. + * But take care that the accessing database is compatible to the real type of OPimRecord !! + * Otherwise this access will be rejected ! + */ bool add( const OPimRecord* ); @@ -176,6 +178,7 @@ public: /** * @internal */ + virtual T cacheFind( int uid )const; void cache( const T& )const; void setSaneCacheSize( int ); @@ -192,6 +195,7 @@ protected: */ BackEnd* backEnd(); BackEnd* m_backEnd; + Cache m_cache; private: @@ -218,7 +222,7 @@ bool OPimAccessTemplate::load() { } template bool OPimAccessTemplate::reload() { - invalidateCache(); // zecke: I think this should be added (se) + invalidateCache(); return m_backEnd->reload(); } template @@ -251,10 +255,22 @@ OPimAccessTemplate::queryByExample( const T& t, int settings, const QDateTime } template T OPimAccessTemplate::find( int uid ) const{ + // First search in cache.. + if ( m_cache.contains( uid ) ) + return m_cache.find( uid ); + T t = m_backEnd->find( uid ); cache( t ); + return t; } + +template +T OPimAccessTemplate::cacheFind( int uid ) const +{ + return m_cache.find( uid ); +} + template T OPimAccessTemplate::find( int uid, const QArray& ar, uint current, typename OTemplateBase::CacheDirection dir )const { @@ -264,7 +280,7 @@ T OPimAccessTemplate::find( int uid, const QArray& ar, * avoid two finds in QCache... */ // owarn << "find it now " << uid << oendl; - if (m_cache.contains( uid ) ) { + if ( m_cache.contains( uid ) ) { return m_cache.find( uid ); } @@ -284,12 +300,14 @@ bool OPimAccessTemplate::add( const T& t ) { } template -bool OPimAccessTemplate::add( const OPimRecord& rec) { +bool OPimAccessTemplate::add( const OPimRecord& rec ) { /* same type */ T tempInstance; if ( rec.rtti() == tempInstance.rtti() ) { const T& t = static_cast(rec); return add(t); + } else { + owarn << "Adding not possible: Objecttype mismatch" << oendl; } return false; } @@ -301,6 +319,8 @@ bool OPimAccessTemplate::add( const OPimRecord* rec) { if ( rec -> rtti() == tempInstance.rtti() ) { const T* t = static_cast(rec); return add( *t ); + } else { + owarn << "Adding not possible: Objecttype mismatch" << oendl; } return false; } -- cgit v0.9.0.2