/** * Intended for development only, checks if the template name matches the case (upper VS lower case letters) of the * actual file name, and if it doesn't, it emulates a file-not-found even if the file system is case insensitive. * This is useful when developing application on Windows, which will be later installed on Linux, OS X, etc. This * check can be resource intensive, as to check the file name the directories involved, up to the * {@link #getBaseDirectory()} directory, must be listed. Positive results (matching case) will be cached without * expiration time. * * <p>The default in {@link FileTemplateLoader} is {@code false}, but subclasses may change they by overriding * {@link #getEmulateCaseSensitiveFileSystemDefault()}. * * @since 2.3.23 */ public void setEmulateCaseSensitiveFileSystem(boolean nameCaseChecked) { // Ensure that the cache exists exactly when needed: if (nameCaseChecked) { if (correctCasePaths == null) { correctCasePaths = new MruCacheStorage(CASE_CHECH_CACHE_HARD_SIZE, CASE_CHECK_CACHE__SOFT_SIZE); } } else { correctCasePaths = null; } this.emulateCaseSensitiveFileSystem = nameCaseChecked; }
public void put(Object key, Object value) { removeClearedReferences(); MruEntry entry = (MruEntry) map.get(key); if (entry == null) { entry = new MruEntry(key, value); map.put(key, entry); linkAfterStrongHead(entry); } else { relinkEntryAfterStrongHead(entry, value); } }
public void remove(Object key) { removeClearedReferences(); removeInternal(key); }
public Object get(Object key) { removeClearedReferences(); MruEntry entry = (MruEntry) map.get(key); if (entry == null) { return null; } relinkEntryAfterStrongHead(entry, null); Object value = entry.getValue(); if (value instanceof MruReference) { // This can only happen with strongSizeLimit == 0 return ((MruReference) value).get(); } return value; }
private void relinkEntryAfterStrongHead(MruEntry entry, Object newValue) { if (unlinkEntryAndInspectIfSoft(entry) && newValue == null) { // Turn soft reference into strong reference, unless is was cleared MruReference mref = (MruReference) entry.getValue(); Object strongValue = mref.get(); if (strongValue != null) { entry.setValue(strongValue); linkAfterStrongHead(entry); } else { map.remove(mref.getKey()); } } else { if (newValue != null) { entry.setValue(newValue); } linkAfterStrongHead(entry); } }
private void removeInternal(Object key) { MruEntry entry = (MruEntry) map.remove(key); if (entry != null) { unlinkEntryAndInspectIfSoft(entry); } }
private void removeClearedReferences() { for (; ; ) { MruReference ref = (MruReference) refQueue.poll(); if (ref == null) { break; } removeInternal(ref.getKey()); } }
/** * Returns a close approximation of the <em>current</em> number of soft cache entries. * * @see #getSoftSizeLimit() * @since 2.3.21 */ public int getSoftSize() { removeClearedReferences(); return softSize; }
public void remove(Object key) { removeClearedReferences(); removeInternal(key); }
public Object get(Object key) { removeClearedReferences(); MruEntry entry = (MruEntry)map.get(key); if(entry == null) { return null; } relinkEntryAfterStrongHead(entry, null); Object value = entry.getValue(); if(value instanceof MruReference) { // This can only happen with maxStrongSize == 0 return ((MruReference)value).get(); } return value; }
private void relinkEntryAfterStrongHead(MruEntry entry, Object newValue) { if(unlinkEntryAndInspectIfSoft(entry) && newValue == null) { // Turn soft reference into strong reference, unless is was cleared MruReference mref = (MruReference)entry.getValue(); Object strongValue = mref.get(); if (strongValue != null) { entry.setValue(strongValue); linkAfterStrongHead(entry); } else { map.remove(mref.getKey()); } } else { if (newValue != null) { entry.setValue(newValue); } linkAfterStrongHead(entry); } }
private void removeInternal(Object key) { MruEntry entry = (MruEntry) map.remove(key); if (entry != null) { unlinkEntryAndInspectIfSoft(entry); } }
private void removeClearedReferences() { for (; ; ) { MruReference ref = (MruReference) refQueue.poll(); if (ref == null) { break; } removeInternal(ref.getKey()); } }
/** * Returns a close approximation of the <em>current</em> number of soft cache entries. * * @see #getSoftSizeLimit() * @since 2.3.21 */ public int getSoftSize() { removeClearedReferences(); return softSize; }
cfg.setCacheStorage(new freemarker.cache.MruCacheStorage(20, Integer.MAX_VALUE));
public void put(Object key, Object value) { removeClearedReferences(); MruEntry entry = (MruEntry)map.get(key); if(entry == null) { entry = new MruEntry(key, value); map.put(key, entry); linkAfterStrongHead(entry); } else { relinkEntryAfterStrongHead(entry, value); } }
static Pattern getPattern(String patternString, int flags) throws TemplateModelException { PatternCacheKey patternKey = new PatternCacheKey(patternString, flags); Pattern result; synchronized (patternCache) { result = (Pattern) patternCache.get(patternKey); } if (result != null) { return result; } try { result = Pattern.compile(patternString, flags); } catch (PatternSyntaxException e) { throw new _TemplateModelException(e, "Malformed regular expression: ", new _DelayedGetMessage(e)); } synchronized (patternCache) { patternCache.put(patternKey, result); } return result; };
public void remove(Object key) { removeClearedReferences(); removeInternal(key); }
public Object get(Object key) { removeClearedReferences(); MruEntry entry = (MruEntry) map.get(key); if (entry == null) { return null; } relinkEntryAfterStrongHead(entry, null); Object value = entry.getValue(); if (value instanceof MruReference) { // This can only happen with strongSizeLimit == 0 return ((MruReference) value).get(); } return value; }