NAME
Langertha::Knarr::TokenStore::Memory - In-memory token store for tests of token_auth
VERSION
version 1.103
SYNOPSIS
use Langertha::Knarr::TokenStore::Memory;
my $store = Langertha::Knarr::TokenStore::Memory->new;
$store->add( token => 'tok-1', model => 'gpt-4o', provider => 'openai',
expires => time + 900 );
$store->revoke( token => 'tok-1' );
$store->notify; # what NOTIFY on the listen channel does
$store->disconnect; # available 0 + invalidate
$store->reconnect;
is $store->lookups, 3; # lookups that reached the store
DESCRIPTION
A Langertha::Knarr::TokenStore that keeps its rows in a hash, with handles to play the database's part: "revoke" changes a row like a DELETE, "notify" is the notification that follows it, "disconnect" and "reconnect" are the connection going away and coming back. Every lookup that reaches the store counts in "lookups", so a test can tell a cache hit (no new lookup) from a miss.
Like Langertha::Knarr::TokenStore::Pg it returns a row only while its expires is in the future, and fails every lookup while it is not "available".
available
True unless "disconnect" was called without a "reconnect" since. Default 1; available => 0 starts disconnected.
lookups
Number of lookups ("lookup_f" and "lookup") that reached the store while it was available.
add
$store->add( token => $token, model => $m, provider => $p, expires => $epoch );
$store->add( hash => $hash_hex, model => $m );
Adds or replaces the row of a token, given as the token itself or as its "hash_token" in Langertha::Knarr::TokenStore. model is required, provider optional, expires (epoch seconds) defaults to 900 seconds from now. Fires no invalidation (a new token cannot be in a cache).
revoke
$store->revoke( token => $token ); # or hash => $hash_hex
Removes the row of a token. Like a DELETE without a trigger, it fires nothing: a caller's cache keeps the row until "notify".
notify
Calls "invalidate" in Langertha::Knarr::TokenStore with notify.
disconnect
Sets "available" to 0 and invalidates with disconnect.
reconnect
Sets "available" back to 1.
SUPPORT
Issues
Please report bugs and feature requests on GitHub at https://github.com/Getty/langertha-knarr/issues.
IRC
Join #langertha on irc.perl.org or message Getty directly.
CONTRIBUTING
Contributions are welcome! Please fork the repository and submit a pull request.
AUTHOR
Torsten Raudssus <torsten@raudssus.de> https://raudssus.de/
COPYRIGHT AND LICENSE
This software is copyright (c) 2026 by Torsten Raudssus.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.