Example #1
0
  @Test
  public void cacheShouldBeClearedAfterModelReload() throws IOException {
    final HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
    final HttpServletResponse response =
        Mockito.mock(HttpServletResponse.class, Mockito.RETURNS_DEEP_STUBS);
    Mockito.when(request.getRequestURI()).thenReturn("/app/g3.css");

    final WroConfiguration config = new WroConfiguration();
    config.setDebug(true);
    config.setDisableCache(false);

    Context.set(Context.webContext(request, response, Mockito.mock(FilterConfig.class)));

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

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

    final ReloadModelRunnable reloadModelRunnable = new ReloadModelRunnable(wroManager);
    reloadModelRunnable.run();
    Assert.assertNull(cacheStrategy.get(new CacheEntry("g3", ResourceType.CSS, true)));
  }
Example #2
0
 /**
  * Check if resources from a group were changed. If a change is detected, the changeListener will
  * be invoked.
  *
  * @param cacheKey the cache key which was requested. The key contains the groupName which has to
  *     be checked for changes.
  */
 public void check(final CacheKey cacheKey, final Callback callback) {
   notNull(cacheKey);
   LOG.debug("started");
   final StopWatch watch = new StopWatch();
   watch.start("detect changes");
   try {
     final Group group =
         new WroModelInspector(modelFactory.create()).getGroupByName(cacheKey.getGroupName());
     if (isGroupChanged(group.collectResourcesOfType(cacheKey.getType()), callback)) {
       callback.onGroupChanged(cacheKey);
       cacheStrategy.put(cacheKey, null);
     }
     resourceChangeDetector.reset();
   } catch (final Exception e) {
     onException(e);
   } finally {
     watch.stop();
     LOG.debug("resource watcher info: {}", watch.prettyPrint());
   }
 }
Example #3
0
 /**
  * Invoked when a resource change detected.
  *
  * @param key {@link CacheKey} which has to be invalidated because the corresponding group
  *     contains stale resources. @VisibleForTesting
  */
 void onGroupChanged(final CacheKey key) {
   LOG.debug("detected change for cacheKey: {}", key);
   cacheStrategy.put(key, null);
 }