缓存每小时更新一次,存储在何处


Cache updated every hour-where to store it?

我有一个python脚本,它(每小时)生成数据,稍后由PHP网页读取。我应该将数据存储在哪里——数据库、文件或其他地方?将有接近100-200KB/用户的数据。哪一个是更好的解决方案?数据不是纯文本,这意味着我必须使用json或xml来存储它

示例数据:(XML很容易阅读,不要怪我!)

    <item uid="1">
<title>Malala's voice stronger, not silenced</title>
<rating>3</rating>
<date>Wednesday, May 8, 2013 2:03 PM</date>
<text>The attack was meant to silence the outspoken teenager who dared to defy the Taliban's ban against girls in school. Instead, it only made Malala's voice more powerful. After a school year that started with a shooting, Malala now eyes a summer of speaking at the U.N., telling her story in a new book and amplifying the issue of girls education.    </text>
</item>

我认为这取决于web应用程序的规模。如果它相当小,并且不会随着时间的推移而变大,那么文件系统就可以了。这是一个很好的选择,因为它很简单。非常容易读取/写入文件。

如果你想要更严重的东西,你可以使用分布式缓存,并只使用一个本地运行的节点来启动它。

有很多选择:

  • Redis(http://redis.io/)
  • 沙发底座(http://www.couchbase.com/)
  • 适用于Windows计算机的应用程序结构(http://en.wikipedia.org/wiki/AppFabric)

现在很多数据库通常支持JSON:

  • MongoDB(http://www.mongodb.org/)
  • 里亚克(http://basho.com/riak/)
  • 沙发数据库(http://couchdb.apache.org/)

我肯定会选择JSON作为您的序列化数据格式。

通常,查询数据库的成本很高,如果最终扩展应用程序,则会遇到问题,因为每次需要读取数据时,也需要查询数据库。这将导致读取数据失败。

有一种技巧可以避免这种情况。它被称为内存缓存。一个很好的memcache介绍可以在Udacity课程中找到,这是第6课。stackoverflow上还有另一篇帖子,解释了他们如何成功地与python和php语言共享memcache。