https://github.com/junbong/idcache
idCache - Policy based identifier generator with cache
https://github.com/junbong/idcache
Last synced: over 1 year ago
JSON representation
idCache - Policy based identifier generator with cache
- Host: GitHub
- URL: https://github.com/junbong/idcache
- Owner: junbong
- License: mit
- Created: 2015-04-24T14:05:52.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2016-04-04T08:16:24.000Z (over 10 years ago)
- Last Synced: 2025-01-24T05:31:50.533Z (over 1 year ago)
- Language: Java
- Size: 24.4 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# idCache
The *idCache* is an policy based identifier generator with cache library written in Java. It is good for item store to giving a unique identifier value to each items. For example, you would like to set SID-stuff identifier- to each items for classify it. In this case, idCache is a good choice. It provides you highly abstracted value generator which take incremental policy.
## Main Goals
* Policy based
* Non-duplicated, unique values
* Concurrency
* Stability
## License
Released under the permissive [MIT License][].
## Usage
### Create simple incremental value generator
```java
// This idCache provides value with incrementing previous by 1
IntIdCache cache = (IntIdCache) IdCaches.newIntIdentifierCacheBuilder()
// Set initial value - it begins with this value
.setInitialValue(10000000)
// Set maximum value - an action performed when value reached
.setMaximumValue(19999999)
// Set increasing policy
.setIncreaser(new SequentialIntIncreaser(1))
// Determine an action when maximum value reached
.setLimitationPolicy(LimitationPolicy.THROW_EXCEPTION_POLICY)
.build();
// 10000000, 10000001, 10000002, 10000003…, 19999999
// an exception occurred when value reached 20000000
// Or simply,
// (in this case, id range is 0 to 10000000)
IntIdCache simpleCache = new IntIdCache(10000000, new SequentialIntIncreaser());
// Or,
// (id range 0 to Integer.MAX_VALUE)
IntIdCache simplestCache = new IntIdCache();
```
### Create random-range incremental value generator
```java
// This idCache provides value with incrementing previous by RANDOM adder
IntIdCache randomCache = new IntIdCache(10000000, 20000000, new RandomLeapIntIncreaser(1, 9));
// 10000000, 10000005, 10000009, 10000012… 19999998
```
[MIT License]: https://github.com/Junbong/idcache/blob/master/LICENSE