有没有办法清除所有会话中的某些会话数据? [英] Is there a way to clear some session data from ALL sessions?

查看:94
本文介绍了有没有办法清除所有会话中的某些会话数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通常,我有以下情况:


  • 从数据库中获取产品及其相关数据

  • 将获取的数据转换为php'product'对象

  • 在会话中缓存产品对象

缓存是只读的,即客户在网站上查看产品。

The cache is readonly, i.e customers viewing products on the site.

但是有诸如 getProductIdsByCategory($ categoryId)和来自这些结果的productIds也按用户缓存,而不使用我已阅读的全局缓存。

But there are calls like getProductIdsByCategory($categoryId) and the productIds from these results are cached too, per user, not using the global cache that I've read about.

一个问题是,如果管理员端添加了一个新产品并将其与某个类别相关联,那么在开始新会话之前,客户将不会在其缓存的 getProductIdsByCategory 中出现新的productId。

A problem is that if someone on the admin side adds a new product and relates it to a category, then customers will not have the new productId come up in their cached getProductIdsByCategory until a new session is started.

当有新产品发布时,是否可以从服务器上的所有会话中清除例如 $ _ SESSION ['x'] 添加?我不想破坏所有会话,因为客户随后将丢失其登录名等。

Is there a way to clear e.g $_SESSION['x'] from ALL sessions on the server when a new product is added? I don't want to destroy all sessions because customers will then lose their logins etc.

还是应该将这些缓存的productId搜索移至全局缓存?

Or should I move these cached productId searches to the global cache?

ps正在使用自定义构建的缓存,而不是内存缓存或类似的缓存。

p.s am using a custom built cache, not memcached or similar.

谢谢

推荐答案

默认情况下,会话数据只是序列化的文件,位于文件系统中的某个位置,可以修改所有会话数据以删除有问题的信息(请注意锁定, (您不参与任何当前打开的会话)。

By default, the session data is just serialized files somewhere in your filesystem, and it is possible to go modify all of them to remove the information in question (respecting locking so that you don't step on any currently open sessions).

不过,我并不推荐这样做。我建议使用一种方法来发出信号,通知应刷新此缓存的数据,例如在 session_start()发生时查看数据库存储的时间戳,以及缓存的数据早于时间戳,缓存被刷新。

I don't really recommend it, though. What I would recommend is making a method of signalling that this cached data should be refreshed, like a database-stored timestamp that gets looked at when session_start() happens, and if the cached data is older than the timestamp, the cache is flushed.

这篇关于有没有办法清除所有会话中的某些会话数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆