Cache
Misago uses caching aggressively to save and re-use results of costful operations like users ACLs resolution.
Setting up cache - ideally memory based one like Redis - is great way to speed up your forum and cut down database traffic.
Note: If you are using Misago-Docker, this is already done without any additional configuration.

Cache versioning

The misago.cache.versions module implements cache versioning feature. Cache version is string made of 8 random characters that should be included in cache key, or as value of version named argument on cache.set and cache.get.
Current cache versions are available under the cache_versions attribute on request. It's set by misago.cache.middleware.cache_versions_middleware middleware.

Invalidating cache

If you wish to invalidate certain versioned cache, you may do it with misago.cache.versions.invalidate_cache function:
1
from misago.cache.versions import invalidate_cache
2
3
4
# Invalidates "bans" cache after creating new ban
5
invalidate_cache("bans")
Copied!

Invalidating all versioned caches

Misago provides two ways for invalidating all versioned caches.

Invalidating all versioned caches from python code

All versioned caches can be invalidated by calling misago.cache.versions.invalidate_all_caches:
1
from misago.cache.versions import invalidate_all_caches
2
3
invalidate_all_caches()
Copied!

Invalidating all versioned caches using management command

Misago has management command that can be executed from console to invalidate all versioned caches:
1
python manage.py invalidateversionedcaches
Copied!

Versioning new caches

misago.cache.operations module provides migration operations that allow you to easily add or remove cache versioning:
1
from django.db import migrations
2
3
from misago.cache.operations import StartCacheVersioning, StopCacheVersioning
4
5
6
class Migration(migrations.Migration):
7
dependencies = [
8
('misago_cache', '0001_initial'),
9
]
10
11
operations = [
12
# Starts cache versioning for "my_cache"
13
StartCacheVersioning("my_cache"),
14
# Stop cache versioning "my_cache"
15
StopCacheVersioning("my_cache"),
16
]
Copied!
In order for your migration to work, you need to declare dependency on misago_cache migration no. 0001_initial.
Last modified 2yr ago