1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.openehealth.ipf.boot.hl7v2;
18
19 import org.openehealth.ipf.commons.ihe.hl7v2.storage.UnsolicitedFragmentationStorage;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
22 import org.springframework.cache.Cache;
23 import org.springframework.cache.CacheManager;
24
25
26
27
28
29
30
31 public class CachingUnsolicitedFragmentionStorage implements UnsolicitedFragmentationStorage {
32
33 private static final transient Logger LOG = LoggerFactory.getLogger(CachingUnsolicitedFragmentionStorage.class);
34 private static final String UNSOLICITED_FRAGMENTATION_STORAGE = "unsolicitedFragmentionStorage";
35 private final Cache cache;
36
37 public CachingUnsolicitedFragmentionStorage(CacheManager cacheManager) {
38 this.cache = cacheManager.getCache(UNSOLICITED_FRAGMENTATION_STORAGE);
39 }
40
41 @Override
42 public void put(String key, StringBuilder accumulator) {
43 cache.put(key, accumulator.toString());
44 }
45
46 @Override
47 public StringBuilder getAndRemove(String key) {
48 String element = cache.get(key, String.class);
49 if (element != null) {
50 cache.evict(key);
51 return new StringBuilder(element);
52 }
53 return null;
54 }
55
56
57 }