summaryrefslogtreecommitdiff
path: root/libopie/pim/opimaccesstemplate.h
authorzecke <zecke>2002-10-10 17:08:58 (UTC)
committer zecke <zecke>2002-10-10 17:08:58 (UTC)
commit1dcc1b1fc9fd35d959255452c8b5be1269ca4f44 (patch) (unidiff)
tree469d239dec74f5751f3aced43c4bae1f0f3a42e3 /libopie/pim/opimaccesstemplate.h
parentaa38f642a07810515dcc18ea38bf520e26d7f88e (diff)
downloadopie-1dcc1b1fc9fd35d959255452c8b5be1269ca4f44.zip
opie-1dcc1b1fc9fd35d959255452c8b5be1269ca4f44.tar.gz
opie-1dcc1b1fc9fd35d959255452c8b5be1269ca4f44.tar.bz2
The Cache is finally in place
I tested it with my todolist and it 'works' for 10.000 todos the hits are awesome ;) The read ahead functionality does not make sense for XMLs backends because most of the stuff is already in memory. While using readahead on SQL makes things a lot faster.... I still have to fully implement read ahead This change is bic but sc
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
@@ -7,6 +7,7 @@
7#include <opie/opimaccessbackend.h> 7#include <opie/opimaccessbackend.h>
8#include <opie/orecordlist.h> 8#include <opie/orecordlist.h>
9 9
10#include "opimcache.h"
10#include "otemplatebase.h" 11#include "otemplatebase.h"
11 12
12/** 13/**
@@ -23,6 +24,7 @@ class OPimAccessTemplate : public OTemplateBase<T> {
23public: 24public:
24 typedef ORecordList<T> List; 25 typedef ORecordList<T> List;
25 typedef OPimAccessBackend<T> BackEnd; 26 typedef OPimAccessBackend<T> BackEnd;
27 typedef OPimCache<T> Cache;
26 28
27 /** 29 /**
28 * our sort order 30 * our sort order
@@ -73,6 +75,12 @@ public:
73 */ 75 */
74 virtual T find( int uid )const; 76 virtual T find( int uid )const;
75 77
78 /**
79 * read ahead cache find method ;)
80 */
81 virtual T find( int uid, const QArray<int>&,
82 uint current, CacheDirection dir = Forward )const;
83
76 /* invalidate cache here */ 84 /* invalidate cache here */
77 /** 85 /**
78 * clears the backend and invalidates the backend 86 * clears the backend and invalidates the backend
@@ -99,6 +107,12 @@ public:
99 * replace T from backend 107 * replace T from backend
100 */ 108 */
101 virtual bool replace( const T& t) ; 109 virtual bool replace( const T& t) ;
110
111 /**
112 * @internal
113 */
114 void cache( const T& )const;
115 void setSaneCacheSize( int );
102protected: 116protected:
103 /** 117 /**
104 * invalidate the cache 118 * invalidate the cache
@@ -111,6 +125,7 @@ protected:
111 */ 125 */
112 BackEnd* backEnd(); 126 BackEnd* backEnd();
113 BackEnd* m_backEnd; 127 BackEnd* m_backEnd;
128 Cache m_cache;
114 129
115}; 130};
116 131
@@ -118,7 +133,8 @@ template <class T>
118OPimAccessTemplate<T>::OPimAccessTemplate( BackEnd* end ) 133OPimAccessTemplate<T>::OPimAccessTemplate( BackEnd* end )
119 : OTemplateBase<T>(), m_backEnd( end ) 134 : OTemplateBase<T>(), m_backEnd( end )
120{ 135{
121 136 if (end )
137 end->setFrontend( this );
122} 138}
123template <class T> 139template <class T>
124OPimAccessTemplate<T>::~OPimAccessTemplate() { 140OPimAccessTemplate<T>::~OPimAccessTemplate() {
@@ -127,6 +143,7 @@ OPimAccessTemplate<T>::~OPimAccessTemplate() {
127} 143}
128template <class T> 144template <class T>
129bool OPimAccessTemplate<T>::load() { 145bool OPimAccessTemplate<T>::load() {
146 invalidateCache();
130 return m_backEnd->load(); 147 return m_backEnd->load();
131} 148}
132template <class T> 149template <class T>
@@ -154,6 +171,26 @@ OPimAccessTemplate<T>::queryByExample( const T& t, int sortOrder ) {
154template <class T> 171template <class T>
155T OPimAccessTemplate<T>::find( int uid ) const{ 172T OPimAccessTemplate<T>::find( int uid ) const{
156 T t = m_backEnd->find( uid ); 173 T t = m_backEnd->find( uid );
174 cache( t );
175 return t;
176}
177template <class T>
178T OPimAccessTemplate<T>::find( int uid, const QArray<int>& ar,
179 uint current, CacheDirection dir )const {
180 /*
181 * better do T.isEmpty()
182 * after a find this way we would
183 * avoid two finds in QCache...
184 */
185 // qWarning("find it now %d", uid );
186 if (m_cache.contains( uid ) ) {
187 qWarning("m cache contains %d", uid);
188 return m_cache.find( uid );
189 }
190
191 T t = m_backEnd->find( uid, ar, current, dir );
192 qWarning("found it and cache it now %d", uid);
193 cache( t );
157 return t; 194 return t;
158} 195}
159template <class T> 196template <class T>
@@ -163,23 +200,26 @@ void OPimAccessTemplate<T>::clear() {
163} 200}
164template <class T> 201template <class T>
165bool OPimAccessTemplate<T>::add( const T& t ) { 202bool OPimAccessTemplate<T>::add( const T& t ) {
203 cache( t );
166 return m_backEnd->add( t ); 204 return m_backEnd->add( t );
167} 205}
168template <class T> 206template <class T>
169bool OPimAccessTemplate<T>::remove( const T& t ) { 207bool OPimAccessTemplate<T>::remove( const T& t ) {
170 return m_backEnd->remove( t.uid() ); 208 return remove( t.uid() );
171} 209}
172template <class T> 210template <class T>
173bool OPimAccessTemplate<T>::remove( int uid ) { 211bool OPimAccessTemplate<T>::remove( int uid ) {
212 m_cache.remove( uid );
174 return m_backEnd->remove( uid ); 213 return m_backEnd->remove( uid );
175} 214}
176template <class T> 215template <class T>
177bool OPimAccessTemplate<T>::replace( const T& t ) { 216bool OPimAccessTemplate<T>::replace( const T& t ) {
217 m_cache.replace( t );
178 return m_backEnd->replace( t ); 218 return m_backEnd->replace( t );
179} 219}
180template <class T> 220template <class T>
181void OPimAccessTemplate<T>::invalidateCache() { 221void OPimAccessTemplate<T>::invalidateCache() {
182 222 m_cache.invalidate();
183} 223}
184template <class T> 224template <class T>
185OPimAccessTemplate<T>::BackEnd* OPimAccessTemplate<T>::backEnd() { 225OPimAccessTemplate<T>::BackEnd* OPimAccessTemplate<T>::backEnd() {
@@ -192,5 +232,16 @@ bool OPimAccessTemplate<T>::wasChangedExternally()const {
192template <class T> 232template <class T>
193void OPimAccessTemplate<T>::setBackEnd( BackEnd* end ) { 233void OPimAccessTemplate<T>::setBackEnd( BackEnd* end ) {
194 m_backEnd = end; 234 m_backEnd = end;
235 if (m_backEnd )
236 m_backEnd->setFrontend( this );
237}
238template <class T>
239void OPimAccessTemplate<T>::cache( const T& t ) const{
240 /* hacky we need to work around the const*/
241 ((OPimAccessTemplate<T>*)this)->m_cache.add( t );
242}
243template <class T>
244void OPimAccessTemplate<T>::setSaneCacheSize( int size ) {
245 m_cache.setSize( size );
195} 246}
196#endif 247#endif