Day 7 Dev Notes

The problem with architecting on the fly, is that it requires a lot of re-work as you work through the design of the solution and have to fix up previously written code. That's the issue I'm dealing with here, but this is all part of the learning experience.

I noticed some caching issues with the posts yesterday, after I was playing around with publishing future posts. This was caused by using the built-in local memory cache in Django, which is process-specific. I didn't really comprehend what this meant until I thought it through as part of my troubleshooting. The problem can occur when using multiple Gunicorn workers, since each one starts up its own process and thus has its own local memory cache. The impact of this is that each process could have a different cache depending on when the cache was set, and then on each page refresh you could see different posts depending on which process you're accessing.

So to work around this issue for now, I've created two config settings:

CACHE_CATEGORIES: bool = True
CACHE_RECENT_PUBLISHED_POSTS: bool = False

The list of categories doesn't change often and doesn't have any complicated rules like the posts can have (e.g. future posts). So I have left the category cache enabled by default for now, but have turned off the posts cache. This can only be set through hard-coding the values in the settings.py file, but that's OK for now since I want to completely refactor this anyway soon.

The other change I made today was to be clearer in the method names about what is being returned. For example, get_published_content() returns all published content, and get_recent_published_content() returns just the recent published content, which is controlled with another new config item: RECENT_PUBLISHED_POSTS_COUNT: int = 20. Previously it wasn't clear whether you were just getting recent posts or all posts. I haven't put too much effort into this right now, since I expect to refactor this again to make it more flexible.

Github link