summaryrefslogtreecommitdiff
path: root/libopie/pim/opimaccesstemplate.h
Side-by-side diff
Diffstat (limited to 'libopie/pim/opimaccesstemplate.h') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie/pim/opimaccesstemplate.h57
1 files changed, 54 insertions, 3 deletions
diff --git a/libopie/pim/opimaccesstemplate.h b/libopie/pim/opimaccesstemplate.h
index 31ab516..92d7192 100644
--- a/libopie/pim/opimaccesstemplate.h
+++ b/libopie/pim/opimaccesstemplate.h
@@ -9,2 +9,3 @@
+#include "opimcache.h"
#include "otemplatebase.h"
@@ -25,2 +26,3 @@ public:
typedef OPimAccessBackend<T> BackEnd;
+ typedef OPimCache<T> Cache;
@@ -75,2 +77,8 @@ public:
+ /**
+ * read ahead cache find method ;)
+ */
+ virtual T find( int uid, const QArray<int>&,
+ uint current, CacheDirection dir = Forward )const;
+
/* invalidate cache here */
@@ -101,2 +109,8 @@ public:
virtual bool replace( const T& t) ;
+
+ /**
+ * @internal
+ */
+ void cache( const T& )const;
+ void setSaneCacheSize( int );
protected:
@@ -113,2 +127,3 @@ protected:
BackEnd* m_backEnd;
+ Cache m_cache;
@@ -120,3 +135,4 @@ OPimAccessTemplate<T>::OPimAccessTemplate( BackEnd* end )
{
-
+ if (end )
+ end->setFrontend( this );
}
@@ -129,2 +145,3 @@ template <class T>
bool OPimAccessTemplate<T>::load() {
+ invalidateCache();
return m_backEnd->load();
@@ -156,2 +173,22 @@ T OPimAccessTemplate<T>::find( int uid ) const{
T t = m_backEnd->find( uid );
+ cache( t );
+ return t;
+}
+template <class T>
+T OPimAccessTemplate<T>::find( int uid, const QArray<int>& ar,
+ uint current, CacheDirection dir )const {
+ /*
+ * better do T.isEmpty()
+ * after a find this way we would
+ * avoid two finds in QCache...
+ */
+ // qWarning("find it now %d", uid );
+ if (m_cache.contains( uid ) ) {
+ qWarning("m cache contains %d", uid);
+ return m_cache.find( uid );
+ }
+
+ T t = m_backEnd->find( uid, ar, current, dir );
+ qWarning("found it and cache it now %d", uid);
+ cache( t );
return t;
@@ -165,2 +202,3 @@ template <class T>
bool OPimAccessTemplate<T>::add( const T& t ) {
+ cache( t );
return m_backEnd->add( t );
@@ -169,3 +207,3 @@ template <class T>
bool OPimAccessTemplate<T>::remove( const T& t ) {
- return m_backEnd->remove( t.uid() );
+ return remove( t.uid() );
}
@@ -173,2 +211,3 @@ template <class T>
bool OPimAccessTemplate<T>::remove( int uid ) {
+ m_cache.remove( uid );
return m_backEnd->remove( uid );
@@ -177,2 +216,3 @@ template <class T>
bool OPimAccessTemplate<T>::replace( const T& t ) {
+ m_cache.replace( t );
return m_backEnd->replace( t );
@@ -181,3 +221,3 @@ template <class T>
void OPimAccessTemplate<T>::invalidateCache() {
-
+ m_cache.invalidate();
}
@@ -194,2 +234,13 @@ void OPimAccessTemplate<T>::setBackEnd( BackEnd* end ) {
m_backEnd = end;
+ if (m_backEnd )
+ m_backEnd->setFrontend( this );
+}
+template <class T>
+void OPimAccessTemplate<T>::cache( const T& t ) const{
+ /* hacky we need to work around the const*/
+ ((OPimAccessTemplate<T>*)this)->m_cache.add( t );
+}
+template <class T>
+void OPimAccessTemplate<T>::setSaneCacheSize( int size ) {
+ m_cache.setSize( size );
}