@@ -151,8 +151,8 @@ public String getFile(String fileCrowdinPath, String crowdinLocale, boolean forc
151151 String postProcessingPath = fileCrowdinPath .replace ("%locale%" , crowdinLocale );
152152 OTACacheControl otaCacheControl = new OTACacheControl ();
153153 // Validating the manifest
154- Long manifestTimestamp = getManifest ().getTimestamp ();
155- if (Long . valueOf ( otaCacheControl .readManifestTimestamp ()). equals ( getManifest ().getTimestamp () ) && !forceFlush ) {
154+ long manifestTimestamp = getManifest ().getTimestamp ();
155+ if (otaCacheControl .readManifestTimestamp () == getManifest ().getTimestamp () && !forceFlush ) {
156156 // Use cache
157157 try {
158158 // Check cache outdated
@@ -162,12 +162,13 @@ public String getFile(String fileCrowdinPath, String crowdinLocale, boolean forc
162162 return new String (otaCacheControl .readObjectCache (postProcessingPath ), StandardCharsets .UTF_8 );
163163 } else {
164164 Util .debugLog ("Local cache outdated for " + postProcessingPath );
165+ Util .debugLog ("Excepted " + otaCacheControl .readCachedObjectTimestamp (postProcessingPath ) + " actual: " + manifestTimestamp );
165166 }
166167 } catch (Exception exception ) {
167168 MsgUtil .debugStackTrace (exception .getStackTrace ());
168169 }
169170 } else {
170- Util .debugLog ("Manifest timestamp check failed " + postProcessingPath + " excepted:" + otaCacheControl .readManifestTimestamp () + " actual: " + getManifest ().getTimestamp ());
171+ Util .debugLog ("Manifest timestamp check failed " + postProcessingPath + " excepted:" + otaCacheControl .readManifestTimestamp () + " actual: " + getManifest ().getTimestamp () + " forceUpdate: " + forceFlush );
171172 }
172173 // Out of the cache
173174 String url = CROWDIN_OTA_HOST + "content" + fileCrowdinPath .replace ("%locale%" , crowdinLocale );
@@ -259,7 +260,7 @@ private String hash(String str) {
259260 }
260261
261262 public long readManifestTimestamp () {
262- return this .metadata .getLong ("manifest.timestamp" , 0 );
263+ return this .metadata .getLong ("manifest.timestamp" , - 1 );
263264 }
264265
265266 public void writeManifestTimestamp (long timestamp ) {
@@ -269,11 +270,10 @@ public void writeManifestTimestamp(long timestamp) {
269270
270271 public long readCachedObjectTimestamp (String path ) {
271272 String cacheKey = hash (path );
272- return this .metadata .getLong ("objects." + cacheKey + ".timestamp" );
273+ return this .metadata .getLong ("objects." + cacheKey + ".time" , - 1 );
273274 }
274275
275- public boolean isCachedObjectOutdated (String path , long manifestTimestamp ) {
276- String cacheKey = hash (path );
276+ public synchronized boolean isCachedObjectOutdated (String path , long manifestTimestamp ) {
277277 return readCachedObjectTimestamp (path ) != manifestTimestamp ;
278278 }
279279
@@ -282,10 +282,10 @@ public byte[] readObjectCache(String path) throws IOException {
282282 return Files .readAllBytes (new File (Util .getCacheFolder (), cacheKey ).toPath ());
283283 }
284284
285- public void writeObjectCache (String path , byte [] data , long manifestTimestamp ) throws IOException {
285+ public synchronized void writeObjectCache (String path , byte [] data , long manifestTimestamp ) throws IOException {
286286 String cacheKey = hash (path );
287287 Files .write (new File (Util .getCacheFolder (), cacheKey ).toPath (), data );
288- this .metadata .set ("objects." + cacheKey , manifestTimestamp );
288+ this .metadata .set ("objects." + cacheKey + ".time" , manifestTimestamp );
289289 save ();
290290 }
291291
0 commit comments