Skip to content

Commit ba1dcc6

Browse files
committed
Allow JSON cache in Docker-mode
(i.e. Docker does not require to use Redis)
1 parent a7c0227 commit ba1dcc6

File tree

7 files changed

+32
-15
lines changed

7 files changed

+32
-15
lines changed

Setup.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ The entire API is bundled in a [Docker Image](https://hub.docker.com/r/kimbtechn
3131
*If hosted in a local network using `all` is recommended.*
3232
- `CONF_STREAM_JSON` Url to a JSON list of streams or `false` to disable (see [Own Streams](#own-streams))
3333
- There are some more options, see defaults in [docker-compose.yml](https://github.com/KIMB-technologies/Radio-API/blob/master/docker-compose.yml).
34+
- The default setup uses Redis for fast caching of values. Redis may be disable by setting `CONF_USE_JSON_CACHE=true`, which enables an json file based caching as fallback (cached items are then stored in `./data/cache`).
3435
- There are two ways to store which episodes of podcasts have already been listened to (new ones are marked by `*`)
3536
- Create a cron job to `/cron.php`, e.g., `docker exec --user www-data radio_api php /cron.php`. (This will dump the already played episodes to a JSON file in `./data/` and *Radio-API* will load the file into redis on container startup).
3637
- Use the data volume of Redis. (Redis will (re-)load its dump files on container startup.)
@@ -80,6 +81,7 @@ The image of [Radio DNS](https://hub.docker.com/r/kimbtechnologies/radio_dns) is
8081
- `CONF_CACHE_DIR` (optional) Change the folder used by the file based cache (defaults to `./data/cache/`).
8182
- `CONF_IM_EXPORT_TOKEN` (optional) Define a token for use with the Im- & Export web interface *Im- & Export* [↓](#im---export).
8283
- **Attention:** Optional parameters have a leading `____` in the default `env.json`, make sure to remove them.
84+
- The `CONF_REDIS_*` values are ignored and `CONF_USE_JSON_CACHE` is always `true`.
8385
- Make sure, that *Radio-API* is available at port `80` for requests with the hostname `*.wifiradiofrontier.com` and `CONF_DOMAIN`.
8486
- Block HTTP access to `./data/` (and `./classes/`) for security reasons (might be omitted in a local network installation).
8587
- Rewrite requests to PHP:

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
2.8.2
1+
2.8.3
22
2.8
33
2

docker-compose.dev.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ services:
2525
- CONF_ALLOWED_DOMAIN=all
2626
- CONF_SHUFFLE_MUSIC=true
2727
- CONF_CACHE_EXPIRE=1200
28+
#- CONF_USE_JSON_CACHE=true
2829
- CONF_REDIS_HOST=redis
2930
- CONF_STREAM_JSON=false #http://192.168.0.10:8081/list.json
3031
- CONF_IM_EXPORT_TOKEN=LP75Djdj195DL8SZnfY3

docker-compose.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ services:
1616
- CONF_ALLOWED_DOMAIN=all # allowed ips for access, list of DynDNS domainnames (divided by ','), or 'all' to allow all ips
1717
- CONF_SHUFFLE_MUSIC=true # random shuffle music in nextcloud radio stations
1818
- CONF_CACHE_EXPIRE=1200 # cache expire time of ips, podcasts, ...
19+
- CONF_USE_JSON_CACHE=false # set to 'true' to disable redis cache and use a simple file-based cache
1920
- CONF_REDIS_HOST=redis # the redis hostname
2021
# - CONF_REDIS_PORT=6379 # default 6379
2122
# - CONF_REDIS_PASS= # default no auth
@@ -24,6 +25,8 @@ services:
2425
# -CONF_IM_EXPORT_TOKEN= # define a token for use with the im-, export web interface at ./gui/im-export.php
2526
depends_on:
2627
- redis
28+
29+
# remove the following part, if 'CONF_USE_JSON_CACHE=true', i.e., redis is not used!
2730
redis:
2831
image: redis:alpine
2932
container_name: radio_api_redis

php/classes/Cache.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ class Cache implements CacheInterface {
128128
private $s;
129129

130130
public function __construct(string $group){
131-
$this->s = DOCKER_MODE ? new RedisCache($group) : new JSONCache($group);
131+
$this->s = DOCKER_MODE && !Config::USE_JSON_CACHE ? new RedisCache($group) : new JSONCache($group);
132132
}
133133
public function getAllKeysOfGroup() : array {
134134
return $this->s->getAllKeysOfGroup();

php/classes/Config.php

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@
6262
!empty($ENV['CONF_IM_EXPORT_TOKEN']) && Helper::checkFilename($ENV['CONF_IM_EXPORT_TOKEN']) && strlen($ENV['CONF_IM_EXPORT_TOKEN']) > 15 ?
6363
$ENV['CONF_IM_EXPORT_TOKEN'] : false
6464
);
65+
define(
66+
'ENV_USE_JSON_CACHE',
67+
!empty($_ENV['CONF_USE_JSON_CACHE']) && $_ENV['CONF_USE_JSON_CACHE'] == 'true'
68+
);
6569

6670
// IP on reverse proxy setup
6771
if( !empty($_SERVER['HTTP_X_REAL_IP']) ){
@@ -77,7 +81,7 @@ class Config {
7781
/**
7882
* The system's version.
7983
*/
80-
const VERSION = 'v2.8.2';
84+
const VERSION = 'v2.8.3';
8185

8286
/**
8387
* The real domain which should be used.
@@ -121,6 +125,11 @@ class Config {
121125
*/
122126
const IM_EXPORT_TOKEN = ENV_IM_EXPORT_TOKEN;
123127

128+
/**
129+
* Always use json cache, even in Docker-Mode
130+
*/
131+
const USE_JSON_CACHE = ENV_USE_JSON_CACHE;
132+
124133
/**
125134
* Store redis cache for ALLOWED_DOMAINS
126135
*/
@@ -192,21 +201,22 @@ public static function checkAccess( ?string $mac = null ) : void {
192201
}
193202

194203
/**
195-
* Sets the redis server copnnection details using the env vars.
204+
* Sets the redis server connection details using the env vars.
196205
* Should be always called before creating a RedisCache.
197206
*/
198207
public static function setRedisServer() : void {
199-
if(!DOCKER_MODE){ // Redis only in Docker mode
200-
return;
201-
}
202-
if( isset( $_ENV['CONF_REDIS_HOST'], $_ENV['CONF_REDIS_PORT'], $_ENV['CONF_REDIS_PASS'] ) ){
203-
RedisCache::setRedisServer($_ENV['CONF_REDIS_HOST'], $_ENV['CONF_REDIS_PORT'], $_ENV['CONF_REDIS_PASS']);
204-
}
205-
else if( isset( $_ENV['CONF_REDIS_HOST'], $_ENV['CONF_REDIS_PORT'] ) ){
206-
RedisCache::setRedisServer($_ENV['CONF_REDIS_HOST'], $_ENV['CONF_REDIS_PORT']);
207-
}
208-
else if( isset( $_ENV['CONF_REDIS_HOST'] ) ){
209-
RedisCache::setRedisServer($_ENV['CONF_REDIS_HOST']);
208+
// Redis only in Docker mode and if not USE_JSON_CACHE
209+
if(DOCKER_MODE && !self::USE_JSON_CACHE){
210+
// configure redis
211+
if( isset( $_ENV['CONF_REDIS_HOST'], $_ENV['CONF_REDIS_PORT'], $_ENV['CONF_REDIS_PASS'] ) ){
212+
RedisCache::setRedisServer($_ENV['CONF_REDIS_HOST'], $_ENV['CONF_REDIS_PORT'], $_ENV['CONF_REDIS_PASS']);
213+
}
214+
else if( isset( $_ENV['CONF_REDIS_HOST'], $_ENV['CONF_REDIS_PORT'] ) ){
215+
RedisCache::setRedisServer($_ENV['CONF_REDIS_HOST'], $_ENV['CONF_REDIS_PORT']);
216+
}
217+
else if( isset( $_ENV['CONF_REDIS_HOST'] ) ){
218+
RedisCache::setRedisServer($_ENV['CONF_REDIS_HOST']);
219+
}
210220
}
211221
}
212222

php/classes/Output.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ class Output {
4444
'Top Click' => ['Top Click', 'Am meisten gehört'],
4545
'Top Vote' => ['Top Vote', 'Am höchsten bewertet'],
4646
'Next Page' => ['Next Page', 'Nächste Seite'],
47+
'You do not have last stations.' => ['You do not have last stations.', 'Sie haben keine zuletzt gehörten Sender!']
4748
);
4849

4950
/**

0 commit comments

Comments
 (0)