Skip to content

Commit

Permalink
Added method to clear oembed and scrape caches
Browse files Browse the repository at this point in the history
  • Loading branch information
cjmalloy committed Jul 25, 2023
1 parent 3446cf1 commit 39ae6f3
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/main/java/jasper/component/WebScraper.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
Expand Down Expand Up @@ -323,6 +324,11 @@ private void parseText(Ref result, Document doc, Scrape config) {
result.setComment(doc.body().wholeText().trim());
}

@CacheEvict(value = "scrape-config", allEntries = true)
public void clearCache() {
logger.info("Cleared scrape config cache.");
}

@Cacheable("scrape-config")
@Transactional(readOnly = true)
@Timed(value = "jasper.service", extraTags = {"service", "scrape"}, histogram = true)
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/jasper/service/OembedService.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Service;
Expand Down Expand Up @@ -60,6 +61,7 @@ public JsonNode get(Map<String, String> params) {
}
}

@CacheEvict(value = {"oembed-provider", "oembed"}, allEntries = true)
@PreAuthorize("hasRole('MOD')")
@Timed(value = "jasper.service", extraTags = {"service", "oembed"}, histogram = true)
public void restoreDefaults() throws IOException {
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/jasper/service/ScrapeService.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,9 @@ public String rss(String url) {
public String cache(byte[] data, String mime) {
return webScraper.cache(from(data, mime)).getUrl();
}

@PreAuthorize("@auth.canAddTag('+plugin/scrape')")
public void clearCache() {
webScraper.clearCache();
}
}
8 changes: 8 additions & 0 deletions src/main/java/jasper/web/rest/ScrapeController.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,12 @@ String cache(
) {
return scrapeService.cache(data, mime);
}

@ApiResponses({
@ApiResponse(responseCode = "204"),
})
@PostMapping("clear-config-cache")
void clearConfigCache() {
scrapeService.clearCache();
}
}

0 comments on commit 39ae6f3

Please sign in to comment.