# Poco

# template < class TKey, class TValue >

# class ExpireStrategy

Library: Foundation
Package: Cache
Header: Poco/ExpireStrategy.h

## Description

An ExpireStrategy implements time based expiration of cache entries

## Inheritance

Direct Base Classes: AbstractStrategy < TKey, TValue >

All Base Classes: AbstractStrategy < TKey, TValue >

## Member Summary

Member Functions: onAdd, onClear, onGet, onIsValid, onRemove, onReplace

## Types Aliases

### ConstIndexIterator

using ConstIndexIterator = typename TimeIndex::const_iterator;

### IndexIterator

using IndexIterator = typename TimeIndex::iterator;

### Iterator

using Iterator = typename Keys::iterator;

### Keys

using Keys = std::map < TKey, IndexIterator >;

### TimeIndex

using TimeIndex = std::multimap < Timestamp, TKey >;

## Constructors

### ExpireStrategy

ExpireStrategy(
Timestamp::TimeDiff expireTimeInMilliSec
);

Create an expire strategy. Note that the smallest allowed caching time is 25ms. Anything lower than that is not useful with current operating systems.

## Destructor

### ~ExpireStrategy

~ExpireStrategy() = default;

## Member Functions

### onAdd

void onAdd(
const void * param254,
const KeyValueArgs < TKey, TValue > & args
);

### onClear

void onClear(
const void * param257,
const EventArgs & args
);

### onGet

void onGet(
const void * param256,
const TKey & key
);

### onIsValid

void onIsValid(
const void * param258,
ValidArgs < TKey > & args
);

### onRemove

void onRemove(
const void * param255,
const TKey & key
);

### onReplace

void onReplace(
const void * param259,
std::set < TKey > & elemsToRemove
);

## Variables

### _expireTime

Timestamp::TimeDiff _expireTime;

### _keyIndex

TimeIndex _keyIndex;

Maps time to key value

### _keys

Keys _keys;

For faster replacement of keys, the iterator points to the _keyIndex map