author | eilers <eilers> | 2004-08-29 12:50:18 (UTC) |
---|---|---|
committer | eilers <eilers> | 2004-08-29 12:50:18 (UTC) |
commit | 679d9fef2673eea18fe5d9c85df2b10b09a8a250 (patch) (side-by-side diff) | |
tree | 8b3d6dbef45568be6f5daac31094d6e599fdefdf /libopie2/opiepim/core | |
parent | 45327ef3c0f093fc227682f79158632afc09e6d1 (diff) | |
download | opie-679d9fef2673eea18fe5d9c85df2b10b09a8a250.zip opie-679d9fef2673eea18fe5d9c85df2b10b09a8a250.tar.gz opie-679d9fef2673eea18fe5d9c85df2b10b09a8a250.tar.bz2 |
Added lookahead caching for addressbook (SQL-only) for speed improvement.
-rw-r--r-- | libopie2/opiepim/core/opimaccesstemplate.h | 40 | ||||
-rw-r--r-- | libopie2/opiepim/core/opimtemplatebase.h | 16 |
2 files changed, 45 insertions, 11 deletions
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 @@ -37,3 +37,2 @@ -#include <opie2/opimcache.h> #include <opie2/opimtemplatebase.h> @@ -130,2 +129,3 @@ public: + /* invalidate cache here */ @@ -141,9 +141,11 @@ public: */ - 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* ); @@ -178,2 +180,3 @@ public: */ + virtual T cacheFind( int uid )const; void cache( const T& )const; @@ -194,2 +197,3 @@ protected: BackEnd* m_backEnd; + Cache m_cache; @@ -220,3 +224,3 @@ template <class T> bool OPimAccessTemplate<T>::reload() { - invalidateCache(); // zecke: I think this should be added (se) + invalidateCache(); return m_backEnd->reload(); @@ -253,6 +257,18 @@ template <class T> T OPimAccessTemplate<T>::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 <class T> +T OPimAccessTemplate<T>::cacheFind( int uid ) const +{ + return m_cache.find( uid ); +} + template <class T> @@ -266,3 +282,3 @@ T OPimAccessTemplate<T>::find( int uid, const QArray<int>& ar, // owarn << "find it now " << uid << oendl; - if (m_cache.contains( uid ) ) { + if ( m_cache.contains( uid ) ) { return m_cache.find( uid ); @@ -286,3 +302,3 @@ bool OPimAccessTemplate<T>::add( const T& t ) { template <class T> -bool OPimAccessTemplate<T>::add( const OPimRecord& rec) { +bool OPimAccessTemplate<T>::add( const OPimRecord& rec ) { /* same type */ @@ -292,2 +308,4 @@ bool OPimAccessTemplate<T>::add( const OPimRecord& rec) { return add(t); + } else { + owarn << "Adding not possible: Objecttype mismatch" << oendl; } @@ -303,2 +321,4 @@ bool OPimAccessTemplate<T>::add( const OPimRecord* rec) { return add( *t ); + } else { + owarn << "Adding not possible: Objecttype mismatch" << oendl; } diff --git a/libopie2/opiepim/core/opimtemplatebase.h b/libopie2/opiepim/core/opimtemplatebase.h index b48dfed..ec9a94e 100644 --- a/libopie2/opiepim/core/opimtemplatebase.h +++ b/libopie2/opiepim/core/opimtemplatebase.h @@ -33,2 +33,3 @@ #include <opie2/opimrecord.h> +#include <opie2/opimcache.h> @@ -72,3 +73,3 @@ private: * internal template base - * T needs to implement the copy c'tor!!! + * Attention: T needs to implement the copy c'tor!!! */ @@ -78,3 +79,5 @@ class OTemplateBase : public OPimBase { public: + /** Look ahead direction of cache */ enum CacheDirection { Forward=0, Reverse }; + OTemplateBase() { @@ -90,2 +93,12 @@ public: uint current, CacheDirection dir = Forward )const = 0; + + /** + * Find in Cache.. + * Returns empty object if nothing found. + */ + virtual T cacheFind( int uid )const = 0; + + /** + * Put element into Cache + */ virtual void cache( const T& )const = 0; @@ -96,2 +109,3 @@ public: static T* rec(); + |