project Websites / Gitlab Issue Listing Script avatar

websites/Gitlab-Issue-Listing-Script#16: Support for Redis or Memcached



Issue Information

Issue Type: issue
Status: closed
Reported By: btasker
Assigned To: btasker

Milestone: v0.4
Created: 21-Oct-21 22:54



Description

We should add the ability to cache the result of API calls for a short time.

This will increase responsiveness, and decrease Gitlab load - particularly for endpoints we call regularly (like fetching project information).



Toggle State Changes

Activity


assigned to @btasker

mentioned in issue #30

Standing up a simple Redis server to test against

docker run -d --name="redis" --restart=always \
-p 6379:6379 \
redis

Turns out I'd completely forgotten what an absolute shit PHP is when it comes to serialising as json. json_encode() will serialise to an object - you can tell json_decode() to deserialise to an array, but if there are objects within that array they'll become arrays again.

The answer, of course, is to use serialize()

I've added some config options:

    // Redis config
    public $redis_enabled = true;
    public $redis_host = 'myhost';
    public $redis_port = 6379;

    // Set this to your redis password if enabled
    public $redis_pass = false;

    // Number of seconds an item in redis is valid for
    public $redis_ttl = 300;

Currently the application will die if it can't reach redis - we might want to make it more graceful than that in future, but dying early is useful for testing

verified

mentioned in commit da1bd070591b0651f2a000435509fbd6c9a3834f

Commit: da1bd070591b0651f2a000435509fbd6c9a3834f 
Author: B Tasker                            
                            
Date: 2022-04-21T18:13:00.000+01:00 

Message

Install and enable the Redis PHP library when building the image (see websites/Gitlab-Issue-Listing-Script#16 )

+5 -1 (6 lines changed)
verified

mentioned in commit ad87ed468811b35e42a748e3bfaa6bbbab977517

Commit: ad87ed468811b35e42a748e3bfaa6bbbab977517 
Author: B Tasker                            
                            
Date: 2022-04-21T18:13:34.000+01:00 

Message

Add support for Redis as a caching layer for websites/Gitlab-Issue-Listing-Script#16

This commit adds new config options and then puts redis calls into callAPI() so that we don't need to make repeated calls out to Gitlab for things that are requested regularly

+43 -2 (45 lines changed)
verified

mentioned in commit 936d24126673b065cb817ab8c918d0aaa57c6f1e

Commit: 936d24126673b065cb817ab8c918d0aaa57c6f1e 
Author: B Tasker                            
                            
Date: 2022-04-21T18:19:12.000+01:00 

Message

Handle an unusable Redis more gracefully for websites/Gitlab-Issue-Listing-Script#16

+12 -3 (15 lines changed)