From b212f666867b1b628c51425aeb56d6ecea16dd41 Mon Sep 17 00:00:00 2001 From: David Russell Date: Thu, 29 Sep 2016 17:04:27 +0700 Subject: [PATCH] Reduced cache interval for print and offline bundles on feature branches. Cache interval for print and offline bundles remains at 20 minutes for master branch. New shorter 20 second cache interval introduced for feature branches to improve developer experience. --- app/com/gitpitch/policies/CacheTimeout.java | 20 ++++++++++++++++++-- app/com/gitpitch/services/PitchService.java | 9 ++++++--- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/app/com/gitpitch/policies/CacheTimeout.java b/app/com/gitpitch/policies/CacheTimeout.java index 722f30a..946d85d 100644 --- a/app/com/gitpitch/policies/CacheTimeout.java +++ b/app/com/gitpitch/policies/CacheTimeout.java @@ -70,14 +70,30 @@ public class CacheTimeout { } } + /* + * Return cache timeout in milliseconds for print PDF file. + */ + public long pdf(PitchParams pp) { + return pp.isMaster() ? PDF_CACHE_MAX_AGE_MASTER : PDF_CACHE_MAX_AGE_BRANCH; + } + + /* + * Return cache timeout in milliseconds for offline ZIP file. + */ + public long zip(PitchParams pp) { + return pp.isMaster() ? ZIP_CACHE_MAX_AGE_MASTER : ZIP_CACHE_MAX_AGE_BRANCH; + } + /* * PDF generation cache timeouts (ms) for PITCHME.pdf. */ - public static final int PDF_CACHE_MAX_AGE = 60 * 1000 * 20; + public static final long PDF_CACHE_MAX_AGE_MASTER = 60 * 1000 * 20; + public static final long PDF_CACHE_MAX_AGE_BRANCH = 20 * 1000; /* * Offline generation cache timeouts (ms) for PITCHME.zip. */ - public static final int ZIP_CACHE_MAX_AGE = 60 * 1000 * 20; + public static final long ZIP_CACHE_MAX_AGE_MASTER = 60 * 1000 * 20; + public static final long ZIP_CACHE_MAX_AGE_BRANCH = 20 * 1000; /* * Long Lived cache timeouts (sec) for GitPitch-owned repos. */ diff --git a/app/com/gitpitch/services/PitchService.java b/app/com/gitpitch/services/PitchService.java index 75c2736..0f0ce86 100644 --- a/app/com/gitpitch/services/PitchService.java +++ b/app/com/gitpitch/services/PitchService.java @@ -191,7 +191,10 @@ public class PitchService { File pdfFile = diskService.asFile(pp, PITCHME_PDF); long pdfAge = System.currentTimeMillis() - pdfFile.lastModified(); - if (pdfAge > cacheTimeout.PDF_CACHE_MAX_AGE) { + log.debug("cachedPDF: pdfAge={}, max={}, file={}", + pdfAge, cacheTimeout.pdf(pp), pdfFile); + + if (pdfAge > cacheTimeout.pdf(pp)) { diskService.delete(pp, PITCHME_PDF); } @@ -235,9 +238,9 @@ public class PitchService { long zipAge = System.currentTimeMillis() - zipFile.lastModified(); log.debug("cachedZip: zipAge={}, max={}, file={}", - zipAge, cacheTimeout.ZIP_CACHE_MAX_AGE, zipFile); + zipAge, cacheTimeout.zip(pp), zipFile); - if (zipAge > cacheTimeout.ZIP_CACHE_MAX_AGE) { + if (zipAge > cacheTimeout.zip(pp)) { diskService.delete(pp, PITCHME_ZIP); diskService.deepDelete(pp, PITCHME_ZIP_DIR); log.debug("cachedZip: deleted expired zip artifacts.");