I am trying to define my own logic of how is cache handled when it is full, because actual behavior is not wanted. I do not know if it is possible (I have not found any documentation on this topic), so I am asking here. When cache is full, Retrofit/OkHttp is removing cached responses based on their validity duration, prioritizing
Tag: caching
Cache is not returning data after expiry even keepDataAfterExpired(true) is set
My Use case: I have to return the updated data from the cache every time without hitting the DB. So i have used RefreshAhead feature of Cache2K. Issue: I am facing few issues. I have kept expiry interval as 1 Minute, eternal = false and keepDataAfterExpired = TRUE. But after 1 Minute when I am trying to get the expired
Caching java instance for peformance
Please assist, What is meant by caching this line/new instance in java for example: I know I have to store insome sort of memory… may someone show me an example. Thanks. Answer Caching means don’t let the garbage collector trashing your variable after you use it, if you already know that you will need to use the same variable a
Java method should cache the results
I’m learning programming in the language java. I need to write an application that takes a string and returns the number of unique characters in the string. It is expected that a string with the same character sequence may be passed several times to the method. Since the counting operation can be time-consuming, the method should cache the results, so
Spring Boot + Infinispan embedded – how to prevent ClassCastException when the object to be cached has been modified?
I have a web application with Spring Boot 2.5.5 and embedded Infinispan 12.1.7. I have a Controller with an endpoint to get a Person object by ID: The following is the PersonService implementation with the use of the @Cacheable annotation on the getPerson method : And here is the Person class: I configured infinispan to use a filesystem-based cache store:
Get map dynamically based on key’s class type and avoid “raw use of parameterized class ‘Map'”
I have a cache class in which I used 2 HashMaps to keep the cache. I want to be able to choose the right map given key’s class type so that: if key is Long, then get value from map longKeyCache if key is String, then get value from map stringKeyCache. (assume user will only pass in Long or String
Should I specify key-type and value-type when using ECache in Spring Boot?
I’ve seen a lot of articles where those parameters where specified, like that: But what is the point of it? Everything seems to work even without them, moreover, if i specify these I have this exception Methods under test ( just call these 2 one by one ): Answer You should probably use two different caches. In the first case,
How to cache methods that return the same list of objects, but based on different conditions?
For example, I have 3 methods. All return data from the same repository and convert it to DTO. How should I annotate them? Would it be ok to annotate all three with the same @Cacheable(“Dishes_DTO”)? And what will happen when one of the methods executes after another, will it override data or make duplicates? Answer In case you use one
How to customize expireAfterWrite for concrete cache if I use cacheBuilder?
Based on this answer I try to use customized expireAfterWrite for “customCache” So my config look like this: Then in codeBase I use: “customCache” And based on my experiments it keeps values on cache pnly 60 seconds by I expect 60 minutes. How to achieve desired result ? Answer I think a better way to do this is as follows.
False sharing and volatile
Good day, I recently found an annotation introduced in Java 8 called Contended. From this mailing list I read what is false sharing and how annotation allows objects or fields to allocate an entire cache line. After some research I found that if two cores store the same cache line and one of them modify it then the second one