如何在数据库中存储轻量级格式(Textile、Markdown)?
我将在我正在从事的项目中实现一种轻量级格式化语言(可能是 Textile,可能是 Markdown),我想知道如何最好地将其存储在数据库中。
如果用户能够编辑他们发布的内容,那么存储原始的、未转换的标记对我来说是有意义的,这样用户下次就不必编辑 HTML。 但由于内容的显示量远多于编辑量,因此存储内容的转换副本也是有意义的,这样就不必在每个页面视图上通过 Textile 发送原始内容。
那么,常见的做法是将原始内容和转换后的内容并排存储在数据库中吗? 有没有更好的办法?
谢谢!
I'm going to be implementing a lightweight formatting language (probably Textile, maybe Markdown) in a project I'm working on, and I'm wonder how best to store it in the database.
If the user is able to edit the content they're posting, it makes sense to me that the original, non-converted markup be stored so that the user doesn't have to edit HTML the next time around. But since the content is going to be displayed a whole lot more than edited, it also makes sense to store a converted copy of the content so that the original doesn't have to be sent through Textile on every page view.
So, is the common practice to store both the original and converted content side-by-side in the database? Is there a better way?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
存储 markdown:
存储 html
两者都存储
你必须权衡你的处理成本与您的存储成本。
Store markdown:
Store html
Store both
You have to weigh up your processing costs vs. your storage cost.
您应该明确存储原始 Textile/Markdown 标记,并使用标准 HTTP 缓存内容(Last-modified、Expires-At、ETag)来缓存渲染的页面或仅缓存处理标记的结果。
You should definetly store original Textile/Markdown markup and use either standard HTTP caching stuff (Last-modified, Expires-At, ETag) to cache rendered pages or just cache the result of processing markup.
我目前正在使用 Markdown 和 PHP。 我将降价源存储在数据库中,并根据请求显示转换后的版本。 我没有任何性能问题,并且对这个设置非常满意。
I'm currently using Markdown with PHP. I store the markdown-source in the database, and I display the Converted Version upon request. I have no performance issues, and am very happy with this setup.
我所看到的确实是将编译后的 HTML 存储在数据库中的单独行中。 只需有一行“content”和另一行“content_html”,并将编译后的 HTML 保存在“content_html”行中。
(您肯定有某种可以重写的保存方法来执行此操作吗?)
What I've seen is indeed to store the compiled HTML in a seperate row in the database. Just have one row 'content' and another 'content_html', and save the compiled HTML in the 'content_html' row.
(Surely you have some kind of save method that you can override to do this?)