Package ro.isdc.wro.cache

Examples of ro.isdc.wro.cache.CacheKey


    final WroManager wroManager = managerFactory.create();
    wroManager.process();

    // use original decorated object because the decorated one trigger the processing for each cache lookup.
    final CacheStrategy<CacheKey, CacheValue> cacheStrategy = AbstractDecorator.getOriginalDecoratedObject(wroManager.getCacheStrategy());
    Assert.assertNotNull(cacheStrategy.get(new CacheKey("g3", ResourceType.CSS, true)));

    final ReloadModelRunnable reloadModelRunnable = new ReloadModelRunnable(wroManager.getModelFactory());
    reloadModelRunnable.run();
    Assert.assertNotNull(cacheStrategy.get(new CacheKey("g3", ResourceType.CSS, true)));
  }
View Full Code Here


    final HttpServletResponse response = context.getResponse();

    OutputStream os = null;
    try {

      final CacheKey cacheKey = getSafeCacheKey(request);
      initAggregatedFolderPath(request, cacheKey.getType());
      final CacheValue cacheValue = cacheStrategy.get(cacheKey);

      // TODO move ETag check in wroManagerFactory
      final String ifNoneMatch = request.getHeader(HttpHeader.IF_NONE_MATCH.toString());

      // enclose etag value in quotes to be compliant with the RFC
      final String etagValue = String.format("\"%s\"", cacheValue.getHash());

      if (etagValue != null && etagValue.equals(ifNoneMatch)) {
        LOG.debug("ETag hash detected: {}. Sending {} status code", etagValue, HttpServletResponse.SC_NOT_MODIFIED);
        response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
        // because we cannot return null, return a stream containing nothing.
        // TODO close output stream?
        return;
      }
      /**
       * Set contentType before actual content is written, solves <br/>
       * <a href="http://code.google.com/p/wro4j/issues/detail?id=341">issue341</a>
       */
      response.setContentType(cacheKey.getType().getContentType() + "; charset=" + configuration.getEncoding());
      // set ETag header
      response.setHeader(HttpHeader.ETAG.toString(), etagValue);

      os = response.getOutputStream();
      if (cacheValue.getRawContent() != null) {
View Full Code Here

      }
    }
  }

  private CacheKey getSafeCacheKey(final HttpServletRequest request) {
    final CacheKey cacheKey = cacheKeyFactory.create(request);
    if (cacheKey == null) {
      throw new WroRuntimeException("Cannot build valid CacheKey from request: " + request.getRequestURI());
    }
    return cacheKey;
  }
View Full Code Here

  /**
   * {@inheritDoc}
   */
  public CacheKey create(final HttpServletRequest request) {
    notNull(request);
    CacheKey key = null;
    final String groupName = groupExtractor.getGroupName(request);
    final ResourceType resourceType = groupExtractor.getResourceType(request);
    final boolean minimize = isMinimized(request);
    if (groupName != null && resourceType != null) {
      key = new CacheKey(groupName, resourceType, minimize);
    }
    return key;
  }
View Full Code Here

   * Based on provided {@link CacheKey} a new key is created which has the same value. This is useful to avoid hashCode
   * variation for minimize flag. This does make sense for resource watcher functionality, when the changes for original
   * resources are performed.
   */
  private static CacheKey createIgnoreMinimizeFlagKey(final CacheKey cacheKey) {
    return new CacheKey(cacheKey.getGroupName(), cacheKey.getType());
  }
View Full Code Here

 
  @Test
  public void testCache()
      throws IOException {
    final HashStrategy builder = new CRC32HashStrategy();
    final CacheKey key = new CacheKey("testGroup", ResourceType.JS, false);
   
    final String content = "var foo = 'Hello World';";
    final String hash = builder.getHash(new ByteArrayInputStream(content.getBytes()));
   
    Assert.assertNull(cache.get(key));
View Full Code Here

  @Test
  public void shouldDetectChangeOfImportedResource()
      throws Exception {
    final String importResourceUri = "imported.css";
    final CacheKey cacheEntry = new CacheKey(GROUP_NAME, ResourceType.CSS, true);
    victim = new ResourceWatcher();
    createDefaultInjector().inject(victim);
    when(mockLocator.locate(Mockito.anyString())).thenAnswer(answerWithContent("initial"));
    when(mockLocator.locate("/" + Mockito.eq(RESOURCE_CSS_URI))).thenAnswer(
        answerWithContent(String.format("@import url(%s)", importResourceUri)));
View Full Code Here

  @Test
  public void shouldCheckForResourceChangeAsynchronously()
      throws Exception {
    Context.get().getConfig().setResourceWatcherAsync(true);
    final CacheKey cacheKey1 = new CacheKey(MIXED_GROUP_NAME, ResourceType.CSS, true);
    final CacheKey cacheKey2 = new CacheKey(MIXED_GROUP_NAME, ResourceType.JS, true);
    // First check is required to ensure that the subsequent changes do not detect any change
    victim.check(cacheKey1);
    victim.check(cacheKey2);

    when(mockLocator.locate(RESOURCE_JS_URI)).thenAnswer(answerWithContent("changed"));
View Full Code Here

    injector.inject(victim);
  }
 
  @Test
  public void shouldReturnEmptyStringWhenGroupHasNoResources() {
    final CacheKey key = new CacheKey(groupName, ResourceType.JS, true);
    Assert.assertEquals(StringUtils.EMPTY, victim.process(key));
  }
View Full Code Here

  @Test(expected = WroRuntimeException.class)
  public void shouldFailWhenGroupHasNoResourcesAndIgnoreEmptyGroupIsFalse() {
    final WroConfiguration config = new WroConfiguration();
    config.setIgnoreEmptyGroup(false);
    initVictim(config);
    final CacheKey key = new CacheKey("group", ResourceType.JS, true);
    victim.process(key);
  }
View Full Code Here

TOP

Related Classes of ro.isdc.wro.cache.CacheKey

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.