@@ -34,16 +34,60 @@ namespace QgsWms
34
34
Q_UNUSED ( version );
35
35
36
36
QgsServerRequest::Parameters params = request.parameters ();
37
+ QString format = params.value ( QStringLiteral ( " FORMAT" ), QStringLiteral ( " PNG" ) );
37
38
38
39
QgsWmsParameters wmsParameters ( QUrlQuery ( request.url () ) );
40
+
41
+ // Get cached image
42
+ QgsAccessControl *accessControl = serverIface->accessControls ();
43
+ QgsServerCacheManager *cacheManager = serverIface->cacheManager ();
44
+ if ( cacheManager )
45
+ {
46
+ ImageOutputFormat outputFormat = parseImageFormat ( format );
47
+ QString saveFormat;
48
+ QString contentType;
49
+ switch ( outputFormat )
50
+ {
51
+ case PNG:
52
+ case PNG8:
53
+ case PNG16:
54
+ case PNG1:
55
+ contentType = " image/png" ;
56
+ saveFormat = " PNG" ;
57
+ break ;
58
+ case JPEG:
59
+ contentType = " image/jpeg" ;
60
+ saveFormat = " JPEG" ;
61
+ break ;
62
+ default :
63
+ throw QgsServiceException ( " InvalidFormat" ,
64
+ QString ( " Output format '%1' is not supported in the GetLegendGraphic request" ).arg ( format ) );
65
+ break ;
66
+ }
67
+
68
+ QImage image;
69
+ QByteArray content = cacheManager->getCachedImage ( project, request, accessControl );
70
+ if ( !content.isEmpty () && image.loadFromData ( content ) )
71
+ {
72
+ response.setHeader ( QStringLiteral ( " Content-Type" ), contentType );
73
+ image.save ( response.io (), qPrintable ( saveFormat ) );
74
+ return ;
75
+ }
76
+ }
77
+
39
78
QgsRenderer renderer ( serverIface, project, wmsParameters );
40
79
41
80
std::unique_ptr<QImage> result ( renderer.getLegendGraphics () );
42
81
43
82
if ( result )
44
83
{
45
- QString format = params.value ( QStringLiteral ( " FORMAT" ), QStringLiteral ( " PNG" ) );
46
84
writeImage ( response, *result, format, renderer.getImageQuality () );
85
+ if ( cacheManager )
86
+ {
87
+ QByteArray content = response.data ();
88
+ if ( !content.isEmpty () )
89
+ cacheManager->setCachedImage ( &content, project, request, accessControl );
90
+ }
47
91
}
48
92
else
49
93
{
0 commit comments