简体   繁体   English

使用缓存创建和更新用户购物车

[英]Using Cache to Create and Update User Cart

I have created an application which has a cart. 我创建了一个具有购物车的应用程序。 Currently the cart is a table in the database. 当前,购物车是数据库中的表。 Each cart is identified by a unique key generated and stored in a session. 每个购物车都由在会话中生成并存储的唯一密钥标识。 However, in order to make interaction with my cart much faster I decided to use cache. 但是,为了使与购物车的交互更快,我决定使用缓存。 However, I have never used it before and I am totally confused as to how it works even though I read all the docs. 但是,我以前从未使用过它,即使我阅读了所有文档,也对它的工作方式完全感到困惑。

For example when I create a cache object is it unique to that user in particular or do I have to generate some form of id to identify user A from user B? 例如,当我创建一个缓存对象时,该对象特别对于该用户而言是唯一的,还是我必须生成某种形式的ID才能从用户B识别用户A?

Both sessions and cache have multiple drivers for storage in Laravel. 会话和高速缓存都具有用于存储在Laravel中的多个驱动程序。 The default driver for both is file. 两者的默认驱动程序是文件。 To speed this up you can choose memcached, redis or apc. 为了加快速度,您可以选择memcached,redis或apc。

Sessions are always specific to one user. 会话始终特定于一个用户。 Cache however is shared over the whole application (for every user). 但是,缓存是在整个应用程序中共享的(对于每个用户)。 For security reasons: store user specific content always in the session! 出于安全考虑:始终在会话中存储用户特定的内容!

So you've to use sessions for this and you can speed up session item look up by changing session storage driver. 因此,您必须为此使用会话,并且可以通过更改会话存储驱动程序来加快会话项查找的速度。 You can configure the session driver in config/session.php 您可以在config/session.phpconfig/session.php会话驱动程序

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM