小编And*_*ler的帖子

Spring 3.1 @Cacheable - 方法仍然执行

我正在尝试实现Spring 3.1缓存,如此此处所述,但它似乎不起作用:我的方法每次都会运行,即使它被标记为@cacheable.我究竟做错了什么?

我已经将它移动到junit测试用例中,并使用自己的配置文件将其与我的应用程序的其余部分隔离开来,但问题仍然存在.以下是相关文件:

弹簧试验servlet.xml中

<beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:cache="http://www.springframework.org/schema/cache"
   xmlns:p="http://www.springframework.org/schema/p"
   xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache.xsd">
<cache:annotation-driven />

<bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheCacheManager" p:cache-manager-ref="ehcache"/>
<bean id="ehcache" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean"
      p:config-location="classpath:ehcache.xml"/>
</beans>
Run Code Online (Sandbox Code Playgroud)

ehcache.xml中

<ehcache>
<diskStore path="java.io.tmpdir"/>
<cache name="cache"
       maxElementsInMemory="100"
       eternal="false"
       timeToIdleSeconds="120"
       timeToLiveSeconds="120"
       overflowToDisk="true"
       maxElementsOnDisk="10000000"
       diskPersistent="false"
       diskExpiryThreadIntervalSeconds="120"
       memoryStoreEvictionPolicy="LRU"/>

</ehcache>
Run Code Online (Sandbox Code Playgroud)

MyTest.java

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration({"classpath:spring-test-servlet.xml"})
@Component
public class MyTest extends TestCase {

    @Test
    public void testCache1(){
        for(int i = 0; i < 5; i++){
            System.out.println("Calling someMethod...");
            System.out.println(someMethod(0));
        }
    }

    @Cacheable("testmethod")
    private int someMethod(int val){
        System.out.println("Not from cache");
        return …
Run Code Online (Sandbox Code Playgroud)

spring caching ehcache

28
推荐指数
1
解决办法
3万
查看次数

离线缓存数据的Firestore定价说明

Firestore会向我收取对本地缓存的数据的读取查询的费用,这对我来说似乎很奇怪,但在Firestore定价文档中,我找不到与之相反的任何说明。如果我强制Firebase进入脱机模式,然后对本地缓存的数据执行读取操作,我是否仍要为检索到的每个单独实体收费?

其次,我的应用程序中的脱机用户将多个小更新写入单个实体。我希望每次都将更改保留在本地(以防它们退出应用程序),但最终只需要最终一致地保存到云中即可。当用户重新连接到Internet并且Firestore刷新了本地更改时,是否将向我收取对该实体的单个写入请求,或者update在脱机时对每个调用收取一次?

Firestore可能很适合我的用例,但是如果离线读写的收费与在线收费相同,那将不是一个负担得起的选择。

firebase google-cloud-firestore

8
推荐指数
2
解决办法
1927
查看次数

Firebase未向REST请求添加CORS标头

有没有办法为REST端点启用CORS,如此此处所述?Firebase似乎不再默认添加它们.对于不需要实时连接或无法使用websockets的应用程序会很有帮助.

这是对Firebase的REST请求.如果您检查响应,则没有cors标题:https://samplechat.firebaseio-demo.com/users/jack/name.json

firebase

3
推荐指数
1
解决办法
2295
查看次数