[openstreetmap/openstreetmap-website] Allows control of cache behavior in the dev env via environment variables (PR #3812)

yuiseki notifications at github.com
Sun Nov 20 14:18:51 UTC 2022


## What

This pull request introduce three new environment variables that allows you to control the cache behavior of this Rails application
- `RAILS_DEV_CACHE`
- `RAILS_PAGE_CACHE`
- `RAILS_FILE_CACHE_DIR`


## Why

This Rails app currently have several problem about caching, especially docker compose environment
- docker compose environment does not persists `/app/tmp` directory
  - This means that the file `/app/tmp/caching-dev.txt` will be lost each time docker compose is restarted
- Even if cache is enabled in the development environment, `config.action_controller.page_cache_directory` is not enabled
- Cache mechanism can only select memory_store, so every cache is lost after restart this rails app


## How

- I've changed `config/environments/development.rb`
  - All changes refer to new environment variables
  - If they are not specified, the behavior is the same as before
- I've added file named `docker-compose.override.example.yml` and edit `.gitignore` to ignore file named `docker-compose.override.yml`
  - The file named `docker-compose.override.yml` can override behavior of the `docker-compose.yml` settings when run-time
  - This is a common way for developers to change the behavior of Docker applications
  - https://docs.docker.com/compose/extends/
  - `docker-compose.override.example.yml` shows how to override `docker-compose.yml` to persists `/app/tmp` dir and to enable environment variables I proposed on this pull request
  - You can use it by `cp docker-compose.override.example.yml docker-compose.override.yml`


## My opinion

- I don't know how the decision was made not to persist /app/tmp in Docker, but this may be a problem
- Adding `docker-compose.override.yml` to `.gitignore` so that it can be freely written is also done in various other projects
- I want to be able to make the cache persistent in my dev env
  - I believe that file_store cache is slower than memory_store cache, but it should be faster than the XML building process on every requests
- Please let me know if you have any comments on the naming of environment variables.


You can view, comment on, or merge this pull request online at:

  https://github.com/openstreetmap/openstreetmap-website/pull/3812

-- Commit Summary --

  * Allows control of cache behavior in the dev env via environment variables

-- File Changes --

    M .gitignore (1)
    M config/environments/development.rb (20)
    A docker-compose.override.example.yml (8)

-- Patch Links --

https://github.com/openstreetmap/openstreetmap-website/pull/3812.patch
https://github.com/openstreetmap/openstreetmap-website/pull/3812.diff

-- 
Reply to this email directly or view it on GitHub:
https://github.com/openstreetmap/openstreetmap-website/pull/3812
You are receiving this because you are subscribed to this thread.

Message ID: <openstreetmap/openstreetmap-website/pull/3812 at github.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstreetmap.org/pipermail/rails-dev/attachments/20221120/5f481b3a/attachment.htm>


More information about the rails-dev mailing list