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

mybatis / caffeine-cache / #198

pending completion
#198

Pull #151

github

web-flow
Merge 9a4ab1f57 into 27599c613
Pull Request #151: Update dependency org.mybatis:mybatis-parent to v38

14 of 15 relevant lines covered (93.33%)

0.93 hits per line

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

93.33
/src/main/java/org/mybatis/caches/caffeine/CaffeineCache.java
1
/*
2
 *    Copyright 2016-2022 the original author or authors.
3
 *
4
 *    Licensed under the Apache License, Version 2.0 (the "License");
5
 *    you may not use this file except in compliance with the License.
6
 *    You may obtain a copy of the License at
7
 *
8
 *       https://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 *    Unless required by applicable law or agreed to in writing, software
11
 *    distributed under the License is distributed on an "AS IS" BASIS,
12
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 *    See the License for the specific language governing permissions and
14
 *    limitations under the License.
15
 */
16
package org.mybatis.caches.caffeine;
17

18
import com.github.benmanes.caffeine.cache.Caffeine;
19

20
import java.util.concurrent.locks.ReadWriteLock;
21

22
import org.apache.ibatis.cache.Cache;
23

24
/**
25
 * Cache adapter for Caffeine.
26
 *
27
 * @author Eddú Meléndez
28
 */
29
public final class CaffeineCache implements Cache {
30

31
  private com.github.benmanes.caffeine.cache.Cache<Object, Object> cache;
32

33
  private String id;
34

35
  /**
36
   * Instantiates a new caffeine cache.
37
   *
38
   * @param id
39
   *          the id
40
   */
41
  public CaffeineCache(String id) {
1✔
42
    if (id == null) {
1✔
43
      throw new IllegalArgumentException("Cache instances require an ID");
1✔
44
    }
45

46
    this.cache = Caffeine.newBuilder().build();
1✔
47
    this.id = id;
1✔
48
  }
1✔
49

50
  @Override
51
  public String getId() {
52
    return this.id;
1✔
53
  }
54

55
  @Override
56
  public void putObject(Object key, Object value) {
57
    this.cache.put(key, value);
1✔
58
  }
1✔
59

60
  @Override
61
  public Object getObject(Object key) {
62
    return this.cache.getIfPresent(key);
1✔
63
  }
64

65
  @Override
66
  public Object removeObject(Object key) {
67
    return this.cache.asMap().remove(key);
1✔
68
  }
69

70
  @Override
71
  public void clear() {
72
    this.cache.invalidateAll();
1✔
73
  }
1✔
74

75
  @Override
76
  public int getSize() {
77
    return (int) this.cache.estimatedSize();
1✔
78
  }
79

80
  @Override
81
  public ReadWriteLock getReadWriteLock() {
82
    return null;
×
83
  }
84

85
}
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