コード例 #1
0
  @Test
  public void contains() {
    final String url = "store://content/url.bin";

    Mockito.when(lookupTable.contains(Key.forUrl(url))).thenReturn(true);
    assertTrue(contentCache.contains(Key.forUrl(url)));
    assertTrue(contentCache.contains(url));

    Mockito.when(lookupTable.contains(Key.forUrl(url))).thenReturn(false);
    assertFalse(contentCache.contains(Key.forUrl(url)));
    assertFalse(contentCache.contains(url));
  }
コード例 #2
0
  private static NodeRef getRootNodeRef() {
    NodeRef rootNodeRef = singletonCache.get(KEY_WEBDAV_ROOT_NODEREF);

    if (rootNodeRef == null) {
      rootNodeRef =
          tenantService.getRootNode(
              nodeService, searchService, namespaceService, rootPath, defaultRootNode);
      singletonCache.put(KEY_WEBDAV_ROOT_NODEREF, rootNodeRef);
    }

    return rootNodeRef;
  }
コード例 #3
0
  @Test(expected = CacheMissException.class)
  public void getReaderForItemInCacheButMissingContentFile() {
    final String url = "store://content/url.bin";
    Mockito.when(lookupTable.contains(Key.forUrl(url))).thenReturn(true);
    final String path = "/no/content/file/at/this/path.bin";
    Mockito.when(lookupTable.get(Key.forUrl(url))).thenReturn(path);

    try {
      contentCache.getReader(url);
    } finally {
      // Important the get(path) was called, so that the timeToIdle is reset
      // for the 'reverse lookup' as well as the URL to path mapping.
      Mockito.verify(lookupTable).get(Key.forCacheFile(path));
    }
  }
コード例 #4
0
  @Test(expected = CacheMissException.class)
  public void getReaderWhenItemNotInCache() {
    final String url = "store://content/url.bin";
    Mockito.when(lookupTable.contains(Key.forUrl(url))).thenReturn(false);

    contentCache.getReader(url);
  }
コード例 #5
0
ファイル: ContentCacheImpl.java プロジェクト: javacx/alfresco
 @Override
 public void remove(String contentUrl) {
   // Remove from the in-memory cache, but not from disk. Let the clean-up process do this
   // asynchronously.
   String path = getCacheFilePath(contentUrl);
   memoryStore.remove(Key.forUrl(contentUrl));
   memoryStore.remove(Key.forCacheFile(path));
 }
コード例 #6
0
  @Test
  public void canGetReaderForItemInCacheHavingLiveFile() {
    final String url = "store://content/url.bin";
    Mockito.when(lookupTable.contains(Key.forUrl(url))).thenReturn(true);
    final String path = tempfile().getAbsolutePath();
    Mockito.when(lookupTable.get(Key.forUrl(url))).thenReturn(path);

    FileContentReader reader = (FileContentReader) contentCache.getReader(url);

    assertEquals("Reader should have correct URL", url, reader.getContentUrl());
    assertEquals(
        "Reader should be for correct cached content file",
        path,
        reader.getFile().getAbsolutePath());
    // Important the get(path) was called, so that the timeToIdle is reset
    // for the 'reverse lookup' as well as the URL to path mapping.
    Mockito.verify(lookupTable).get(Key.forCacheFile(path));
  }
コード例 #7
0
  @Test
  public void getCacheFilePath() {
    final String url = "store://some/url.bin";
    final String expectedPath = "/some/cache/file/path";
    Mockito.when(lookupTable.get(Key.forUrl(url))).thenReturn(expectedPath);

    String path = contentCache.getCacheFilePath(url);

    assertEquals("Paths must match", expectedPath, path);
  }
コード例 #8
0
  @Test
  public void getContentUrl() {
    final File cacheFile = new File("/some/path");
    final String expectedUrl = "store://some/url";
    Mockito.when(lookupTable.get(Key.forCacheFile(cacheFile))).thenReturn(expectedUrl);

    String url = contentCache.getContentUrl(cacheFile);

    assertEquals("Content URLs should match", expectedUrl, url);
  }
コード例 #9
0
ファイル: ContentCacheImpl.java プロジェクト: javacx/alfresco
  @Override
  public ContentReader getReader(String contentUrl) {
    Key url = Key.forUrl(contentUrl);
    if (memoryStore.contains(url)) {
      String path = memoryStore.get(url);

      // Getting the path for a URL from the memoryStore will reset the timeToIdle for
      // that URL. It is important to perform a reverse lookup as well to ensure that the
      // cache file path to URL mapping is also kept in the cache.
      memoryStore.get(Key.forCacheFile(path));

      File cacheFile = new File(path);
      if (cacheFile.exists()) {
        return new FileContentReader(cacheFile, contentUrl);
      }
    }

    throw new CacheMissException(contentUrl);
  }
コード例 #10
0
  @Test
  public void remove() {
    final String url = "store://some/url.bin";
    final String path = "/some/path";
    Mockito.when(lookupTable.get(Key.forUrl(url))).thenReturn(path);

    contentCache.remove(url);

    Mockito.verify(lookupTable).remove(Key.forUrl(url));
    Mockito.verify(lookupTable).remove(Key.forCacheFile(path));
  }
コード例 #11
0
  /* (non-Javadoc)
   * @see org.alfresco.repo.tenant.TenantService#getTenant(java.lang.String)
   */
  public Tenant getTenant(String tenantDomain) {
    tenantDomain = getTenantDomain(tenantDomain);
    Tenant tenant = tenantsCache.get(tenantDomain);
    if (tenant == null) {
      // backed by TenantAdminService - update this cache, e.g. could have been invalidated and/or
      // expired
      if (tenantAdminService != null) {
        tenant = tenantAdminService.getTenant(tenantDomain);
        if (tenant == null) {
          throw new AlfrescoRuntimeException("No such tenant " + tenantDomain);
        } else {
          putTenant(tenantDomain, tenant);
        }
      }
    }

    return tenant;
  }
コード例 #12
0
ファイル: ContentCacheImpl.java プロジェクト: javacx/alfresco
 /**
  * Get a content URL from the cache - keyed by File.
  *
  * @param file
  * @return
  */
 public String getContentUrl(File file) {
   return memoryStore.get(Key.forCacheFile(file));
 }
コード例 #13
0
ファイル: ContentCacheImpl.java プロジェクト: javacx/alfresco
 // Not part of the ContentCache interface as this breaks encapsulation.
 // Handy method for tests though, since it allows us to find out where
 // the content was cached.
 protected String cacheFileLocation(String url) {
   return memoryStore.get(Key.forUrl(url));
 }
コード例 #14
0
ファイル: ContentCacheImpl.java プロジェクト: javacx/alfresco
 private void recordCacheEntries(String contentUrl, File cacheFile) {
   memoryStore.put(Key.forUrl(contentUrl), cacheFile.getAbsolutePath());
   memoryStore.put(Key.forCacheFile(cacheFile), contentUrl);
 }
コード例 #15
0
ファイル: ContentCacheImpl.java プロジェクト: javacx/alfresco
 @Override
 public boolean contains(String contentUrl) {
   return memoryStore.contains(Key.forUrl(contentUrl));
 }
コード例 #16
0
ファイル: ContentCacheImpl.java プロジェクト: javacx/alfresco
 /**
  * Allows caller to perform lookup using a {@link Key}.
  *
  * @param key
  * @return true if the cache contains, false otherwise.
  */
 public boolean contains(Key key) {
   return memoryStore.contains(key);
 }
コード例 #17
0
ファイル: ContentCacheImpl.java プロジェクト: javacx/alfresco
 /**
  * Put an item in the lookup table.
  *
  * @param key
  * @param value
  */
 public void putIntoLookup(Key key, String value) {
   memoryStore.put(key, value);
 }
コード例 #18
0
ファイル: ContentCacheImpl.java プロジェクト: javacx/alfresco
 /**
  * Get the path of a cache file for the given content URL - will return null if there is no entry
  * in the cache for the specified URL.
  *
  * @param contentUrl
  * @return cache file path
  */
 public String getCacheFilePath(String contentUrl) {
   return memoryStore.get(Key.forUrl(contentUrl));
 }
コード例 #19
0
 // should only be called by Tenant Admin Service
 protected void putTenant(String tenantDomain, Tenant tenant) {
   if (logger.isDebugEnabled()) {
     logger.debug("putTenant " + tenantDomain);
   }
   tenantsCache.put(tenantDomain, tenant);
 }
コード例 #20
0
 // should only be called by Tenant Admin Service
 protected void removeTenant(String tenantDomain) {
   if (logger.isDebugEnabled()) {
     logger.debug("removeTenant " + tenantDomain);
   }
   tenantsCache.remove(tenantDomain);
 }
コード例 #21
0
 /** Remove all items from the lookup table. Cached content files are not removed. */
 public void removeAll() {
   memoryStore.clear();
 }