/* * @see org.alfresco.repo.content.ContentStore#delete(java.lang.String) */ @Override public boolean delete(String contentUrl) { ReentrantReadWriteLock readWriteLock = readWriteLock(contentUrl); ReadLock readLock = readWriteLock.readLock(); readLock.lock(); try { if (!cache.contains(contentUrl)) { // The item isn't in the cache, so simply delete from the backing store return backingStore.delete(contentUrl); } } finally { readLock.unlock(); } WriteLock writeLock = readWriteLock.writeLock(); writeLock.lock(); try { // Double check the content still exists in the cache if (cache.contains(contentUrl)) { // The item is in the cache, so remove. cache.remove(contentUrl); } // Whether the item was in the cache or not, it must still be deleted from the backing store. return backingStore.delete(contentUrl); } finally { writeLock.unlock(); } }
private ContentReader attemptCacheAndRead(String url) { ContentReader reader = null; try { if (!cache.contains(url)) { if (cache.put(url, backingStore.getReader(url))) { reader = cache.getReader(url); } } else { reader = cache.getReader(url); } } catch (CacheMissException e) { cache.remove(url); } return reader; }
/* * @see org.alfresco.repo.content.ContentStore#getReader(java.lang.String) */ @Override public ContentReader getReader(String contentUrl) { // Use pool of locks - which one is determined by a hash of the URL. // This will stop the content from being read/cached multiple times from the backing store // when it should only be read once - cached versions should be returned after that. ReadLock readLock = readWriteLock(contentUrl).readLock(); readLock.lock(); try { if (cache.contains(contentUrl)) { return cache.getReader(contentUrl); } } catch (CacheMissException e) { // Fall through to cacheAndRead(url); } finally { readLock.unlock(); } return cacheAndRead(contentUrl); }