如何更改 hdiv 中的缓存删除策略
我正在为 java Web 应用程序使用 HDIV Web 应用程序安全框架。每个新的网页请求都会生成 hdiv 内部安全信息,这些信息会被缓存并用于安全检查。
我有以下场景:
我有一个订单页面,当向购物车添加商品或从购物车中删除商品时,该页面会弹出 2 秒钟的确认页面。
弹出 50 次后,底层订单页面将从缓存中删除,因此应用程序中会出现错误。
有人知道如何影响 hdiv 缓存删除策略以保持基页存活吗?
一种解决方法是将 org.hdiv.session.StateCache.maxSize 从 50 增加到 500。
但这只能治标不治本。
更新:
使用@rbelasko解决方案 我成功使用原始的 org.hdiv.session.StateCache 将 maxSize 更改为 20 并在调试日志中验证缓存条目在 20 个条目后被消除。
当我将其更改为使用我自己的实现时,它不起作用
Bean 定义
<bean id="cache" class="com.mycompany.session.StateCacheTest" singleton="false"
init-method="init">
<property name="maxSize">
<value>20</value>
</property>
</bean>
我自己的类
public class StateCacheTest extends StateCache
{
private static final Log log = LogFactory.getLog(StateCacheTest.class);
public StateCacheTest()
{
log.debug("StateCache()");
}
@Override
public void setMaxSize(final int maxSize)
{
super.setMaxSize(maxSize);
if (log.isDebugEnabled())
{
log.debug("setMaxSize to " + maxSize);
}
}
}
在调试日志中没有来自 StateCacheTest 的条目
有什么想法吗?
更新2:
虽然我无法通过spring加载不同的IStateCache实现,但我能够使用
<hdiv:config ... maxPagesPerSession="200" ... />
bean设置定义
<property name="maxSize">
<value>20</value>
</property>
来降低此错误的可能性,这对我系统中的缓存大小没有影响。
I am using the HDIV Web Application Security Framework for a java web application. Every new web-page-request generates hdiv-internal security information that is cached and used for security checks.
I have the following szenario:
I have one order page that pops up a confirmation-page for 2 seconds when something was added to or removed from the cart.
after 50 popups the the underlaying order page is removed from the cache and therefor an error occurs in the app.
does anybody know how to influence the hdiv cache-removal strategy to keep the basepage alive?
One way around is to increase org.hdiv.session.StateCache.maxSize from 50 to 500.
but this would only cure the symptoms not the underlying cause.
Update:
using @rbelasko solution
I succeded to use the original org.hdiv.session.StateCache
to change the maxSize to 20 and verified in the debug-log that the cachentries are dismissed after 20 entries.
When I changed it to use my own implementation it didn-t work
Bean definition
<bean id="cache" class="com.mycompany.session.StateCacheTest" singleton="false"
init-method="init">
<property name="maxSize">
<value>20</value>
</property>
</bean>
My own class
public class StateCacheTest extends StateCache
{
private static final Log log = LogFactory.getLog(StateCacheTest.class);
public StateCacheTest()
{
log.debug("StateCache()");
}
@Override
public void setMaxSize(final int maxSize)
{
super.setMaxSize(maxSize);
if (log.isDebugEnabled())
{
log.debug("setMaxSize to " + maxSize);
}
}
}
In the debug-log were no entries from StateCacheTest
Any ideas?
Update 2:
While i was not able to load a different IStateCache implementation via spring i was able to make this error less likely using
<hdiv:config ... maxPagesPerSession="200" ... />
the bean-settings definition
<property name="maxSize">
<value>20</value>
</property>
had no effect on the cachesize in my system.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以创建自定义 IStateCache接口实现。
使用 HDIV 显式配置(不使用 HDIV 的新自定义模式),这是“缓存”bean 的默认配置:
您可以创建自己的实现并实现适合您要求的策略。
问候,
罗伯托
You could create a custom IStateCache interface implementation.
Using the HDIV explicit configuration (not using HDIV's new custom schema) this is the default configuration for "cache" bean:
You could create your own implementation and implement the strategy that fits your requirements.
Regards,
Roberto