net.markenwerk:utils-lrucache

A simple LRU cache for Java

License

License

Categories

Categories

Net
GroupId

GroupId

net.markenwerk
ArtifactId

ArtifactId

utils-lrucache
Last Version

Last Version

1.0.1
Release Date

Release Date

Type

Type

jar
Description

Description

net.markenwerk:utils-lrucache
A simple LRU cache for Java
Project URL

Project URL

https://github.com/markenwerk/java-utils-lrucache
Project Organization

Project Organization

Markenwerk – Gesellschaft für markenbildende Maßnahmen mbH
Source Code Management

Source Code Management

https://github.com/markenwerk/java-utils-lrucache

Download utils-lrucache

How to add to project

<!-- https://jarcasting.com/artifacts/net.markenwerk/utils-lrucache/ -->
<dependency>
    <groupId>net.markenwerk</groupId>
    <artifactId>utils-lrucache</artifactId>
    <version>1.0.1</version>
</dependency>
// https://jarcasting.com/artifacts/net.markenwerk/utils-lrucache/
implementation 'net.markenwerk:utils-lrucache:1.0.1'
// https://jarcasting.com/artifacts/net.markenwerk/utils-lrucache/
implementation ("net.markenwerk:utils-lrucache:1.0.1")
'net.markenwerk:utils-lrucache:jar:1.0.1'
<dependency org="net.markenwerk" name="utils-lrucache" rev="1.0.1">
  <artifact name="utils-lrucache" type="jar" />
</dependency>
@Grapes(
@Grab(group='net.markenwerk', module='utils-lrucache', version='1.0.1')
)
libraryDependencies += "net.markenwerk" % "utils-lrucache" % "1.0.1"
[net.markenwerk/utils-lrucache "1.0.1"]

Dependencies

test (1)

Group / Artifact Type Version
junit : junit jar 4.12

Project Modules

There are no modules declared in this project.

A simple LRU cache for Java

Build Status Coverage Status Dependency Status Maven Central Issues MIT License

This library provides a simple LRU cache based on a linked hash map.

Overview

This library is hosted in the Maven Central Repository. You can use it with the following coordinates:

<dependency>
	<groupId>net.markenwerk</groupId>
	<artifactId>utils-lrucache</artifactId>
	<version>1.0.1</version>
</dependency>

Consult the usage description and Javadoc for further information.

Motivation

As every Java programmer should know, it is possible to create a simple LRU cache from a LinkedHashMap with a few lines of code. The goal of this library is to provide a ready made LRU cache, so that is isn't necessary to reproduce these few lines of code every time and have an appropriately named class.

Usage

LRU caching

This library provides the simple LruCache which is a LinkedHashMap that is configured to hold it's entries in access order and evicts the least recently accessed entry, if the configured cache size is exceeded.

// the desired cache size
int cacheSize = ...

// a map that never holds more than cacheSize elements
Map<String, Object> cache = new LruCache<>(cacheSize);

Listening to eviction events

A LruCache can be created with a LruCacheListener that gets notified, when an entry is evicted from the LruCache.

// the desired cache size
int cacheSize = ...

// a map that never holds more than cacheSize elements
Map<String, Object> cache = new LruCache<>(
	cacheSize,
	entry -> System.out.println(entry.getKey() + " got evicted")
);
net.markenwerk

Markenwerk

Versions

Version
1.0.1
1.0.0