expiring-cache

A very simple cache that supports expiring entries by based on a TTL.

License

License

GroupId

GroupId

com.jolira
ArtifactId

ArtifactId

expiring-cache
Last Version

Last Version

1.0.16
Release Date

Release Date

Type

Type

jar
Description

Description

expiring-cache
A very simple cache that supports expiring entries by based on a TTL.
Project URL

Project URL

http://github.com/jolira/expiring-cache
Source Code Management

Source Code Management

http://github.com/jolira/expiring-cache

Download expiring-cache

How to add to project

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

Dependencies

test (1)

Group / Artifact Type Version
junit : junit jar 4.8.2

Project Modules

There are no modules declared in this project.

Expiring Cache

Sometimes it is good to have a cache that contains entries that expire. This is a simple implementation of such as cache which has served me well in very, very big applications for several years now.

This component is available in Maven Central.

A usage example (from the tests):

    private ExpiringCache<Integer, String> loadOneThousand(final long ttl,
            final int maxSize) {
        final ExpiringCache<Integer, String> map = new ExpiringCache<Integer, String>(
                ttl, maxSize);

        for (int idx = 0; idx < ONETHOUSAND; idx++) {
            map.put(Integer.valueOf(idx), Integer.toHexString(idx));
        }

        return map;
    }
    
    final Map<Integer, String> map1 = loadOneThousand(Integer.MAX_VALUE);
    final String val1 = map1.get(Integer.valueOf(255));

    assertEquals("ff", val1);

    final Map<Integer, String> map2 = loadOneThousand(1);

    Thread.sleep(10);

    final String val2 = map2.get(Integer.valueOf(255));

    assertNull(val2);
com.jolira

Jolira

Versions

Version
1.0.16
1.0.15
1.0.14