### Question:
CacheHelper extends BasicSectionHelper { public void invalidateFragments() { if (fragments == null) { return; } fragments.clear(); }  @Override void execute(Options options); void init(); @Override Set<ConfigurationKey> getConfigurationKeys(); @Override void validate(HelperDefinition definition); void invalidateFragments(); void invalidateFragments(final String keyPart); static final ConfigurationKey FRAGMENT_CACHE_MAX_SIZE_KEY; }### Answer:
@Test public void testHelper() throws InterruptedException { final MustacheEngine engine = MustacheEngineBuilder.newBuilder() .registerHelpers(HelpersBuilder.empty().addCache().build()) .build(); CacheHelper cacheHelper = (CacheHelper) engine.getConfiguration() .getHelpers().get(HelpersBuilder.CACHE); final AtomicInteger hits = new AtomicInteger(); Mustache mustache = engine.compileMustache("cache_01", "{{#cache}}{{this.age}}{{/cache}}"); Hammer hammer = new Hammer() { @Override public Integer getAge() { hits.incrementAndGet(); return super.getAge(); } }; assertEquals("10", mustache.render(hammer)); assertEquals("10", mustache.render(hammer)); hammer.setAge(11); assertEquals("10", mustache.render(hammer)); assertEquals(1, hits.get()); cacheHelper.invalidateFragments(); hammer.setAge(1); mustache = engine.compileMustache("cache_02", "{{#cache expire=1 unit='MILLISECONDS'}}{{this.age}}{{/cache}}"); assertEquals("1", mustache.render(hammer)); Thread.sleep(50); hammer.setAge(2); assertEquals("2", mustache.render(hammer)); cacheHelper.invalidateFragments(); hammer.setAge(5); mustache = engine.compileMustache("cache_03", "{{#cache guard=this.age}}{{this.age}}{{/cache}}"); assertEquals("5", mustache.render(hammer)); assertEquals("5", mustache.render(hammer)); hammer.setAge(50); assertEquals("50", mustache.render(hammer)); cacheHelper.invalidateFragments(); mustache = engine.compileMustache("cache_04", "{{#cache key=this.id}}{{this.age}}{{/cache}}"); hammer.setAge(1000); Hammer hammer2 = new Hammer(2000) { @Override public Integer getAge() { hits.incrementAndGet(); return super.getAge(); } }; Hammer hammer3 = new Hammer(3000) { @Override public Integer getAge() { hits.incrementAndGet(); return super.getAge(); } }; assertEquals("1000", mustache.render(hammer)); assertEquals("2000", mustache.render(hammer2)); assertEquals("3000", mustache.render(hammer3)); hammer.setAge(1001); hammer2.setAge(2001); hammer3.setAge(3001); assertEquals("1000", mustache.render(hammer)); assertEquals("2000", mustache.render(hammer2)); assertEquals("3000", mustache.render(hammer3)); cacheHelper.invalidateFragments(hammer.getId()); assertEquals("1001", mustache.render(hammer)); assertEquals("2000", mustache.render(hammer2)); assertEquals("3000", mustache.render(hammer3)); }