• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

alibaba / jetcache / #405

16 Apr 2024 05:58AM UTC coverage: 0.0% (-88.9%) from 88.866%
#405

push

areyouok
add encoding to fix coverage report

0 of 5353 relevant lines covered (0.0%)

0.0 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/jetcache-core/src/main/java/com/alicp/jetcache/CacheUtil.java
1
package com.alicp.jetcache;
2

3
import com.alicp.jetcache.event.CacheEvent;
4
import com.alicp.jetcache.event.CacheLoadAllEvent;
5
import com.alicp.jetcache.event.CacheLoadEvent;
6

7
import java.util.Map;
8
import java.util.Set;
9
import java.util.function.Consumer;
10
import java.util.function.Function;
11

12
/**
13
 * Created on 2017/5/22.
14
 *
15
 * @author huangli
16
 */
17
public class CacheUtil {
×
18

19
    private interface ProxyLoader<K, V> extends CacheLoader<K, V> {
20
    }
21

22
    public static <K, V> ProxyLoader<K, V> createProxyLoader(Cache<K, V> cache,
23
                                                             CacheLoader<K, V> loader,
24
                                                             Consumer<CacheEvent> eventConsumer) {
25
        if (loader instanceof ProxyLoader) {
×
26
            return (ProxyLoader<K, V>) loader;
×
27
        }
28
        return new ProxyLoader<K, V>() {
×
29
            @Override
30
            public V load(K key) throws Throwable {
31
                long t = System.currentTimeMillis();
×
32
                V v = null;
×
33
                boolean success = false;
×
34
                try {
35
                    v = loader.load(key);
×
36
                    success = true;
×
37
                } finally {
38
                    t = System.currentTimeMillis() - t;
×
39
                    CacheLoadEvent event = new CacheLoadEvent(cache, t, key, v, success);
×
40
                    eventConsumer.accept(event);
×
41
                }
42
                return v;
×
43
            }
44

45
            @Override
46
            public Map<K, V> loadAll(Set<K> keys) throws Throwable {
47
                long t = System.currentTimeMillis();
×
48
                boolean success = false;
×
49
                Map<K, V> kvMap = null;
×
50
                try {
51
                    kvMap = loader.loadAll(keys);
×
52
                    success = true;
×
53
                } finally {
54
                    t = System.currentTimeMillis() - t;
×
55
                    CacheLoadAllEvent event = new CacheLoadAllEvent(cache, t, keys, kvMap, success);
×
56
                    eventConsumer.accept(event);
×
57
                }
58
                return kvMap;
×
59
            }
60

61
            @Override
62
            public boolean vetoCacheUpdate() {
63
                return loader.vetoCacheUpdate();
×
64
            }
65
        };
66
    }
67

68
    public static <K, V> ProxyLoader<K, V> createProxyLoader(Cache<K, V> cache,
69
                                                          Function<K, V> loader,
70
                                                          Consumer<CacheEvent> eventConsumer) {
71
        if (loader instanceof ProxyLoader) {
×
72
            return (ProxyLoader<K, V>) loader;
×
73
        }
74
        if (loader instanceof CacheLoader) {
×
75
            return createProxyLoader(cache, (CacheLoader) loader, eventConsumer);
×
76
        }
77
        return k -> {
×
78
            long t = System.currentTimeMillis();
×
79
            V v = null;
×
80
            boolean success = false;
×
81
            try {
82
                v = loader.apply(k);
×
83
                success = true;
×
84
            } finally {
85
                t = System.currentTimeMillis() - t;
×
86
                CacheLoadEvent event = new CacheLoadEvent(cache, t, k, v, success);
×
87
                eventConsumer.accept(event);
×
88
            }
89
            return v;
×
90
        };
91
    }
92

93

94
    public static <K, V> AbstractCache<K, V> getAbstractCache(Cache<K, V> c) {
95
        while (c instanceof ProxyCache) {
×
96
            c = ((ProxyCache) c).getTargetCache();
×
97
        }
98
        return (AbstractCache) c;
×
99
    }
100

101
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc