In my application, I chose markdown as the format for some texts.
Obviously, parsing the text takes some time.
The question is, is it worth caching it? And if so, where? Text file or database?
As I see it, I have three options:
-
Don’t cache. Run the parsing each time the text pulled from the database and displayed.
(In Symfony2/Twig, I’d just do{{ text|markdown }}) -
Have two fields in the database,
content_sourceandcontent_parsed. Each time the text is editted, save the parsed code and when requested, simply display the cached code. -
Cache the parsed code as a file. When requested, check if the file exists (if not, parse it and cache it) and display it.
Thoughts?
Personally, I would store both the source and the parsed content in a database, unless the content gets to be large. Parsing each time is going to be a big scalability problem.
And,it depends on whether you need access to the original content. When I’ve been in similar situations, I find that we might make changes to how we parse such content, and need to go back and re-parse all of the old content, so its definitely handy to keep the original content around.