]> git.proxmox.com Git - ceph.git/blame - ceph/src/rocksdb/java/src/main/java/org/rocksdb/LRUCache.java
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / rocksdb / java / src / main / java / org / rocksdb / LRUCache.java
CommitLineData
7c673cae 1// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
11fdf7f2
TL
2// This source code is licensed under both the GPLv2 (found in the
3// COPYING file in the root directory) and Apache 2.0 License
4// (found in the LICENSE.Apache file in the root directory).
7c673cae
FG
5
6package org.rocksdb;
7
8/**
9 * Least Recently Used Cache
10 */
11public class LRUCache extends Cache {
12
13 /**
14 * Create a new cache with a fixed size capacity
15 *
16 * @param capacity The fixed size capacity of the cache
17 */
18 public LRUCache(final long capacity) {
1e59de90 19 this(capacity, -1, false, 0.0, 0.0);
7c673cae
FG
20 }
21
22 /**
23 * Create a new cache with a fixed size capacity. The cache is sharded
24 * to 2^numShardBits shards, by hash of the key. The total capacity
25 * is divided and evenly assigned to each shard.
26 * numShardBits = -1 means it is automatically determined: every shard
27 * will be at least 512KB and number of shard bits will not exceed 6.
28 *
29 * @param capacity The fixed size capacity of the cache
30 * @param numShardBits The cache is sharded to 2^numShardBits shards,
31 * by hash of the key
32 */
33 public LRUCache(final long capacity, final int numShardBits) {
1e59de90 34 super(newLRUCache(capacity, numShardBits, false, 0.0, 0.0));
7c673cae
FG
35 }
36
37 /**
38 * Create a new cache with a fixed size capacity. The cache is sharded
39 * to 2^numShardBits shards, by hash of the key. The total capacity
40 * is divided and evenly assigned to each shard. If strictCapacityLimit
41 * is set, insert to the cache will fail when cache is full.
42 * numShardBits = -1 means it is automatically determined: every shard
43 * will be at least 512KB and number of shard bits will not exceed 6.
44 *
45 * @param capacity The fixed size capacity of the cache
46 * @param numShardBits The cache is sharded to 2^numShardBits shards,
47 * by hash of the key
48 * @param strictCapacityLimit insert to the cache will fail when cache is full
49 */
50 public LRUCache(final long capacity, final int numShardBits,
51 final boolean strictCapacityLimit) {
1e59de90 52 super(newLRUCache(capacity, numShardBits, strictCapacityLimit, 0.0, 0.0));
7c673cae
FG
53 }
54
55 /**
56 * Create a new cache with a fixed size capacity. The cache is sharded
57 * to 2^numShardBits shards, by hash of the key. The total capacity
58 * is divided and evenly assigned to each shard. If strictCapacityLimit
59 * is set, insert to the cache will fail when cache is full. User can also
60 * set percentage of the cache reserves for high priority entries via
61 * highPriPoolRatio.
62 * numShardBits = -1 means it is automatically determined: every shard
63 * will be at least 512KB and number of shard bits will not exceed 6.
64 *
65 * @param capacity The fixed size capacity of the cache
66 * @param numShardBits The cache is sharded to 2^numShardBits shards,
67 * by hash of the key
68 * @param strictCapacityLimit insert to the cache will fail when cache is full
69 * @param highPriPoolRatio percentage of the cache reserves for high priority
70 * entries
71 */
1e59de90
TL
72 public LRUCache(final long capacity, final int numShardBits, final boolean strictCapacityLimit,
73 final double highPriPoolRatio) {
74 super(newLRUCache(capacity, numShardBits, strictCapacityLimit, highPriPoolRatio, 0.0));
75 }
76
77 /**
78 * Create a new cache with a fixed size capacity. The cache is sharded
79 * to 2^numShardBits shards, by hash of the key. The total capacity
80 * is divided and evenly assigned to each shard. If strictCapacityLimit
81 * is set, insert to the cache will fail when cache is full. User can also
82 * set percentage of the cache reserves for high priority entries and low
83 * priority entries via highPriPoolRatio and lowPriPoolRatio.
84 * numShardBits = -1 means it is automatically determined: every shard
85 * will be at least 512KB and number of shard bits will not exceed 6.
86 *
87 * @param capacity The fixed size capacity of the cache
88 * @param numShardBits The cache is sharded to 2^numShardBits shards,
89 * by hash of the key
90 * @param strictCapacityLimit insert to the cache will fail when cache is full
91 * @param highPriPoolRatio percentage of the cache reserves for high priority
92 * entries
93 * @param lowPriPoolRatio percentage of the cache reserves for low priority
94 * entries
95 */
96 public LRUCache(final long capacity, final int numShardBits, final boolean strictCapacityLimit,
97 final double highPriPoolRatio, final double lowPriPoolRatio) {
98 super(newLRUCache(
99 capacity, numShardBits, strictCapacityLimit, highPriPoolRatio, lowPriPoolRatio));
7c673cae
FG
100 }
101
1e59de90
TL
102 private native static long newLRUCache(final long capacity, final int numShardBits,
103 final boolean strictCapacityLimit, final double highPriPoolRatio,
104 final double lowPriPoolRatio);
7c673cae
FG
105 @Override protected final native void disposeInternal(final long handle);
106}