简体   繁体   English

如何使用Wicket 7使图像可缓存?

[英]How can I make an image cacheable with Wicket 7?

I have png files both in the file system and in a database. 我在文件系统和数据库中都有png文件。 So I tried to use 所以我试着用

ByteArrayResource 使用ByteArrayResource

which displayed the image only once. 它只显示一次图像。 A browser refresh only showed an image placeholder. 浏览器刷新仅显示图像占位符。 The image url had a parameter appended: 图片网址附加了一个参数:

&antiCache=123456789 &antiCache = 123456789

So ByteArrayResource looks to me like it can only be used once and has to be reloaded even when the page only gets refresehd. 所以ByteArrayResource看起来像我只能使用一次,即使页面只获得refresehd也必须重新加载。 Next I tried 接下来我试过了

PackageResource PackageResource

which displayed the image in the browser (even after a refresh) but also rendered the "antiCache" parameter. 它在浏览器中显示图像(即使刷新后),但也呈现“antiCache”参数。 This happened even after explicitly calling 甚至在明确调用之后也发生了

setCachingEnable( true );

Also "PackageResource" cannot use my png data from the database. “PackageResource”也不能使用我的数据库中的png数据。

The antiCache parameter is added only in Ajax responses. antiCache参数仅在Ajax响应中添加。 If you add the image in the Ajax response ( https://github.com/apache/wicket/blob/70606d73e9165d37c1d8b7c7820279fb4be18770/wicket-core/src/main/java/org/apache/wicket/markup/html/image/Image.java#L543 ) then Wicket assumes that it has to be repainted, so it modifies the url. 如果您在Ajax响应中添加图像( https://github.com/apache/wicket/blob/70606d73e9165d37c1d8b7c7820279fb4be18770/wicket-core/src/main/java/org/apache/wicket/markup/html/image/Image。 java#L543 )然后Wicket假定它必须重新绘制,因此它修改了url。 You can override this method and suppress this behavior. 您可以覆盖此方法并禁止此行为。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM