From 732d1b8441e9f63607a4c624714671c6650bb8b3 Mon Sep 17 00:00:00 2001 From: Julian Maurice Date: Fri, 15 Nov 2024 10:38:36 +0100 Subject: [PATCH] Bug 38454: [DO NOT PUSH] Add API route to showcase the bug This route fetches a value from the memory cache, increment it, store it in memory cache and return the incremented value. If the memory cache was flushed before every request, the route should always return "1". Instead it returns "1" at the first request, "2" at the second request, and so on Test plan: 1. Start the REST API app: `api/v1/app.pl daemon -l http://*:3000` 2. Use curl to request the app: `curl http://localhost:3000/memlite-counter` --- Koha/REST/V1.pm | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Koha/REST/V1.pm b/Koha/REST/V1.pm index 52bd15697e..469e755da0 100644 --- a/Koha/REST/V1.pm +++ b/Koha/REST/V1.pm @@ -160,6 +160,18 @@ sub startup { $self->plugin('Koha::REST::Plugin::Responses'); $self->plugin('Koha::REST::Plugin::Auth::IdP'); $self->plugin( 'Mojolicious::Plugin::OAuth2' => $oauth_configuration ); + + $self->routes->get( + '/memlite-counter' => sub { + my $c = shift; + require Koha::Cache::Memory::Lite; + my $cache = Koha::Cache::Memory::Lite->get_instance(); + my $counter = $cache->get_from_cache('memlite-counter') // 0; + $counter = $counter + 1; + $cache->set_in_cache('memlite-counter', $counter); + $c->render( text => "$counter\n" ); + } + ); } 1; -- 2.39.2