简体   繁体   中英

How can I make an image cacheable with Wicket 7?

I have png files both in the file system and in a database. So I tried to use

ByteArrayResource

which displayed the image only once. A browser refresh only showed an image placeholder. The image url had a parameter appended:

&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. Next I tried

PackageResource

which displayed the image in the browser (even after a refresh) but also rendered the "antiCache" parameter. This happened even after explicitly calling

setCachingEnable( true );

Also "PackageResource" cannot use my png data from the database.

The antiCache parameter is added only in Ajax responses. 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. You can override this method and suppress this behavior.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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