Skip to content

Redis "volatile-lru" cache#407

Open
annehaley wants to merge 3 commits into
masterfrom
redis-cache-2
Open

Redis "volatile-lru" cache#407
annehaley wants to merge 3 commits into
masterfrom
redis-cache-2

Conversation

@annehaley

Copy link
Copy Markdown
Collaborator

This PR bumps the version of large-image we use so that we can leverage the latest changes to its Redis cache. Since the cache entries will now have a TTL, we can use the "volatile-lru" max memory policy and expect that our redis cache can evict large-image tiles without evicting websocket connections.

See x and x. Resolves #398.

@annehaley annehaley requested review from brianhelba and manthey June 25, 2026 17:39
@brianhelba

Copy link
Copy Markdown
Collaborator

Why not just do this through the Django cache framework, which is the default for django-large-image?

@annehaley

Copy link
Copy Markdown
Collaborator Author

Why not just do this through the Django cache framework, which is the default for django-large-image?

We're currently using the Django cache, but in production when a user tries to visualize the boston orthoimagery layer for our example use cases, the web service with Django runs out of memory: Process running mem=895M(122.6%) Error R14 (Memory quota exceeded).

@brianhelba

Copy link
Copy Markdown
Collaborator

I see that after #404, the Django cache is being used, but it was never actually configured properly.

Per my suggestion, #404 needed to add something like:

LARGE_IMAGE_CACHE_NAME = "tiles"

CACHES = {
    "tiles": {
        "BACKEND": "django.core.cache.backends.redis.RedisCache",
        "LOCATION": env.url("DJANGO_REDIS_URL").geturl(),
        "OPTIONS": {
            # Use database /2 for the tile cache,
            # in case other services use /0 in the future
            "db": "2",
        },
        # An arbitrarily long time
        "TIMEOUT": int(datetime.timedelta(weeks=4).total_seconds()),
    }
}

If we need to balance other cache considerations in the future, the configuration is well-documented by Django and we have all the local knobs (including the actual TIMEOUT) to adjust things.

Comment thread uvdat/settings/base.py

# Large image cache with Redis
LARGE_IMAGE_CACHE_BACKEND = "redis"
LARGE_IMAGE_CACHE_REDIS_URL = env.url("DJANGO_REDIS_URL").geturl()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where do we control the Redis database number here?

We're using Redis for other things, so I think we should have local control of this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Set Redis Max Memory Policy

3 participants