Skip to content

Commit 059232a

Browse files
committed
[Server][Feature][needs-docs] Server Cache can be used for images (tiles)
Extending cache manager to save adn retrieve images.
1 parent 385de9d commit 059232a

File tree

4 files changed

+163
-1
lines changed

4 files changed

+163
-1
lines changed

src/server/qgsservercachefilter.cpp

+35
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,38 @@ bool QgsServerCacheFilter::deleteCachedDocuments( const QgsProject *project ) co
6161
Q_UNUSED( project );
6262
return false;
6363
}
64+
65+
//! Returns cached image
66+
QByteArray QgsServerCacheFilter::getCachedImage( const QgsProject *project, const QgsServerRequest &request, const QString &key ) const
67+
{
68+
Q_UNUSED( project );
69+
Q_UNUSED( request );
70+
Q_UNUSED( key );
71+
return QByteArray();
72+
}
73+
74+
//! Updates or inserts the image in cache
75+
bool QgsServerCacheFilter::setCachedImage( const QByteArray *img, const QgsProject *project, const QgsServerRequest &request, const QString &key ) const
76+
{
77+
Q_UNUSED( img );
78+
Q_UNUSED( project );
79+
Q_UNUSED( request );
80+
Q_UNUSED( key );
81+
return false;
82+
}
83+
84+
//! Deletes the cached image
85+
bool QgsServerCacheFilter::deleteCachedImage( const QgsProject *project, const QgsServerRequest &request, const QString &key ) const
86+
{
87+
Q_UNUSED( project );
88+
Q_UNUSED( request );
89+
Q_UNUSED( key );
90+
return false;
91+
}
92+
93+
//! Deletes all cached images for a QGIS project
94+
bool QgsServerCacheFilter::deleteCachedImages( const QgsProject *project ) const
95+
{
96+
Q_UNUSED( project );
97+
return false;
98+
}

src/server/qgsservercachefilter.h

+36-1
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,46 @@ class SERVER_EXPORT QgsServerCacheFilter
8282

8383
/**
8484
* Deletes all cached documents for a QGIS project
85-
* \param project the project used to generate the document to provide path
85+
* \param project the project used to generate the documents to provide path
8686
* \returns true if the documents have been deleted
8787
*/
8888
virtual bool deleteCachedDocuments( const QgsProject *project ) const;
8989

90+
/**
91+
* Returns cached image (or 0 if document not in cache) like tiles
92+
* \param project the project used to generate the image to provide path
93+
* \param request the request used to generate the image to provider parameters or data
94+
* \param key the key provided by the access control to identify differents images for the same request
95+
* \returns QByteArray of the cached image or an empty one if no corresponding image found
96+
*/
97+
virtual QByteArray getCachedImage( const QgsProject *project, const QgsServerRequest &request, const QString &key ) const;
98+
99+
/**
100+
* Updates or inserts the image in cache like tiles
101+
* \param img the document to cache
102+
* \param project the project used to generate the image to provide path
103+
* \param request the request used to generate the image to provider parameters or data
104+
* \param key the key provided by the access control to identify differents images for the same request
105+
* \returns true if the image has been cached
106+
*/
107+
virtual bool setCachedImage( const QByteArray *img, const QgsProject *project, const QgsServerRequest &request, const QString &key ) const;
108+
109+
/**
110+
* Deletes the cached image
111+
* \param project the project used to generate the image to provide path
112+
* \param request the request used to generate the image to provider parameters or data
113+
* \param key the key provided by the access control to identify differents images for the same request
114+
* \returns true if the image has been deleted
115+
*/
116+
virtual bool deleteCachedImage( const QgsProject *project, const QgsServerRequest &request, const QString &key ) const;
117+
118+
/**
119+
* Deletes all cached images for a QGIS project
120+
* \param project the project used to generate the images to provide path
121+
* \returns true if the images have been deleted
122+
*/
123+
virtual bool deleteCachedImages( const QgsProject *project ) const;
124+
90125
private:
91126

92127
//! The server interface

src/server/qgsservercachemanager.cpp

+57
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,63 @@ bool QgsServerCacheManager::deleteCachedDocuments( const QgsProject *project ) c
7575
return false;
7676
}
7777

78+
//! Returns cached image (or 0 if image not in cache) like tiles
79+
QByteArray QgsServerCacheManager::getCachedImage( const QgsProject *project, const QgsServerRequest &request, const QString &key ) const
80+
{
81+
QgsServerCacheFilterMap::const_iterator scIterator;
82+
for ( scIterator = mPluginsServerCaches->constBegin(); scIterator != mPluginsServerCaches->constEnd(); ++scIterator )
83+
{
84+
QByteArray content = scIterator.value()->getCachedImage( project, request, key );
85+
if ( !content.isEmpty() )
86+
{
87+
return content;
88+
}
89+
}
90+
return QByteArray();
91+
}
92+
93+
//! Updates or inserts the image in cache like tiles
94+
bool QgsServerCacheManager::setCachedImage( const QByteArray *img, const QgsProject *project, const QgsServerRequest &request, const QString &key ) const
95+
{
96+
QgsServerCacheFilterMap::const_iterator scIterator;
97+
for ( scIterator = mPluginsServerCaches->constBegin(); scIterator != mPluginsServerCaches->constEnd(); ++scIterator )
98+
{
99+
if ( scIterator.value()->setCachedImage( img, project, request, key ) )
100+
{
101+
return true;
102+
}
103+
}
104+
return false;
105+
}
106+
107+
//! Deletes the cached image
108+
bool QgsServerCacheManager::deleteCachedImage( const QgsProject *project, const QgsServerRequest &request, const QString &key ) const
109+
{
110+
QgsServerCacheFilterMap::const_iterator scIterator;
111+
for ( scIterator = mPluginsServerCaches->constBegin(); scIterator != mPluginsServerCaches->constEnd(); ++scIterator )
112+
{
113+
if ( scIterator.value()->deleteCachedImage( project, request, key ) )
114+
{
115+
return true;
116+
}
117+
}
118+
return false;
119+
}
120+
121+
//! Deletes all cached images for a QGIS Project
122+
bool QgsServerCacheManager::deleteCachedImages( const QgsProject *project ) const
123+
{
124+
QgsServerCacheFilterMap::const_iterator scIterator;
125+
for ( scIterator = mPluginsServerCaches->constBegin(); scIterator != mPluginsServerCaches->constEnd(); ++scIterator )
126+
{
127+
if ( scIterator.value()->deleteCachedImages( project ) )
128+
{
129+
return true;
130+
}
131+
}
132+
return false;
133+
}
134+
78135
//! Register a new access control filter
79136
void QgsServerCacheManager::registerServerCache( QgsServerCacheFilter *serverCache, int priority )
80137
{

src/server/qgsservercachemanager.h

+35
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,41 @@ class SERVER_EXPORT QgsServerCacheManager
101101
*/
102102
bool deleteCachedDocuments( const QgsProject *project ) const;
103103

104+
/**
105+
* Returns cached image (or 0 if image not in cache) like tiles
106+
* \param project the project used to generate the image to provide path
107+
* \param request the request used to generate the image to provider parameters or data
108+
* \param key the key provided by the access control to identify differents images for the same request
109+
* \returns the cached image or 0 if no corresponding image found
110+
*/
111+
QByteArray getCachedImage( const QgsProject *project, const QgsServerRequest &request, const QString &key ) const;
112+
113+
/**
114+
* Updates or inserts the image in cache like tiles
115+
* \param img the image to cache
116+
* \param project the project used to generate the image to provide path
117+
* \param request the request used to generate the image to provider parameters or data
118+
* \param key the key provided by the access control to identify differents images for the same request
119+
* \returns true if the image has been cached
120+
*/
121+
bool setCachedImage( const QByteArray *img, const QgsProject *project, const QgsServerRequest &request, const QString &key ) const;
122+
123+
/**
124+
* Deletes the cached image
125+
* \param project the project used to generate the image to provide path
126+
* \param request the request used to generate the image to provider parameters or data
127+
* \param key the key provided by the access control to identify differents images for the same request
128+
* \returns true if the image has been deleted
129+
*/
130+
bool deleteCachedImage( const QgsProject *project, const QgsServerRequest &request, const QString &key ) const;
131+
132+
/**
133+
* Deletes all cached images for a QGIS project
134+
* \param project the project used to generate the images to provide path
135+
* \returns true if the images have been deleted
136+
*/
137+
bool deleteCachedImages( const QgsProject *project ) const;
138+
104139
/**
105140
* Register a server cache filter
106141
* \param serverCache the server cache to add

0 commit comments

Comments
 (0)