Skip to content

Latest commit

 

History

History
31 lines (26 loc) · 1.11 KB

README.md

File metadata and controls

31 lines (26 loc) · 1.11 KB

plucker

Cache java methods with just annotation

Java CI with Maven

annotate any method with @Cached

  @Cached(duration = 1, durationUnit = TimeUnit.HOURS, maximumSize = 10000L)
  public Map<String, Object> methodThatTakesTooMuchTime(String objId) throws InterruptedException {
    final Map<String, Object> stringObjectMap = Collections.synchronizedMap(new HashMap<String, Object>());
    stringObjectMap.put("name", "steve");
    stringObjectMap.put("data", new HashSet<String>() {{
      add("one");
      add("two");
    }});
    TimeUnit.SECONDS.sleep(3);
    return stringObjectMap;
  }

use it as mentioned below

  public void test_methodThatTakesTooMuchTime() {
    assertTrue(TestCacheService.getInstance().getListOfStuff("key") != null);
    assertTrue(TestCacheService.getInstance().getListOfStuff("x") != null);
    System.out.println("one = " + TestCacheService.getInstance().methodThatTakesTooMuchTime("one"));
    System.out.println("one = " + TestCacheService.getInstance().methodThatTakesTooMuchTime("one"));
  }