Set standard cache policy in Apollo Kotlin? - graphql

Instead of setting the cache policy per query, is it possible to set a standard cache policy?

Related

What are the pros and cons of using TTL vs actively sending a request to invalidate a key to invalidate a key in a cache?

Are there any best practices around key invalidation for caches like Redis? Should I let the key fall out after the TTL expires or should I call a delete on the key in question to remove that key from cache?
Would the actively calling a delete operation put more load and hurt the throughput of my cache?
It seems you are asking around how to handle memory management in Redis when using it as a cache. Redis implements some configurations maxmemory , maxmemory-policy, maxmemory-samples, replica-ignore-maxmemory, and active-expire-effort. For more details on these see the self documentation for your version.
Redis configs allow you to manage tradeoffs on CPU, memory and latency without needing to do external memory management. With that said DEL can be used to invalidate keys when your application is aware of state changes. And the TTLs set can be used with some of the memory management policies.

CaffeineCacheManager vs SimpleCacheManager

May I know different between CaffeineCacheManager and SimpleCacheManager?
As description CaffeineCacheManager is Lazy cache, but what is lazy cache, in what situation I should pick CaffeineCacheManager?
Have a read of all the different cache providers first and notice how their APIs differ. The Simple Cache manager is Spring's default cache manager that's used if you don't specify a cache manager. It's 'simple' because its underlying implementation uses a Java ConcurrentHashMap and it doesn't give you a whole lot of customization options.
The Caffeine Cache manager is slightly different in that there a more configuration-driven customization options such as having the ability to specify the cache timeout expiry limit (in order to 'bust' the cache after a certain time period) and the cache maximum size limit in order to limit the capacity of the cache. The default cache manager does not give you this configurability.
My team used the Caffeine Cache manager on a project recently and I can definitely recommend it.
In terms of your question about a 'lazy' cache. Have a read of lazy instatiation more broadly. Essentially it only loads what it needs when it needs it (upon a cache access) rather than loading the entire thing all at once.

How can I cache network data in service worker?

I have created Progressive Web Application (PWA) with angular 5.0 and .net core 2.0. It works fine in offline mode. But only static data are cached for offline mode. I need to store previously requested network data in service worker cache, so that I can fetch these data through service worker cache in offline mode.
You can use also angular service worker for it.
Data Groups - Cache External API Data
The data groups config allows you to cache external API calls, which makes it possible for your app to use an external data source without a network connection. This data is not known at build-time, so it can only be cached at runtime. There are two possible strategies for caching data sources - freshness and performance.
api-freshness - This freshness strategy will attempt to serve data from the network first, then fallback to th cache. You can set a maxAge property that defines how long to cache responses and a timeout that defines how long to wait before falling back to the cache.
api-performance - The performance cache will serve data from the cache first and only reach out to the network if the cache is expired.
Example you could find here in section ngsw-config.json.
Try to check HTTP Caching.
All you need to do is ensure that each server response provides the
correct HTTP header directives to instruct the browser on when and for
how long the browser can cache the response.
For further info, you can check the whole documentation. It provides example and illustrations to understand better about HTTP Caching.

SalesForce integration - notify external system on SF object definition change

We have a software that is integrated with SalesForce using SF SOAP API. As we are sending/receiving data to/from SF on user level, we must know which SF objects and object fields is user allowed to access (based on SF visibility rules). Therefore, we first invoke describeSObject(objName) and store it to our cache to speed up integration.
What happens is, when our clients change visibility rules or rename object fields on SF side, they must invalidate cache in our application. If they forget to do that (and they usually do), we are not aware that our cache is invalid.
Question: is there a way to invoke our web service from SF when visibility rules changes, or object field is added/deleted/renamed? If that is possible, as visibility rules in SF are quite complex, how can we differ which users are affected by change (so we do not invalidate cache for everyone)?
I suspect you can't currently.
As an alternative, catch the exceptions that occur due to the metadata mismatch and flush the local cache for that user. Then retry the original request with the updated metadata.

How to make a cache entry in websphere not to expire

I have created a cache in the web sphere which will be shared by multiple applications and i wanted to make one entry in the created cache to not to expire. How can i make it ?
Thanks and Regards,
Sunny.
Are you deriving/using WebSpheres dyna-cache (DistributedObjectCache)? How are you creating your cache instance?
The DistributedObjectCache (through it's DistributedMap parent) defines a "put" method overload that accepts a TTL for the individual cache entry. If you want to set the TTL for the entire cache, there is conversely a setTimeToLive(int) method in DistributedMap
see http://publib.boulder.ibm.com/infocenter/dmndhelp/v6rxmx/index.jsp?topic=/com.ibm.wsps.602.javadoc.doc/doc/com/ibm/websphere/cache/DistributedMap.html
Worth noting is that the TTL is not available as a configuration option in the cacheinstances.properties (or the admin console Resources/Cache Instances/Object cache instances), it has to be set programatically using setTimeToLive()

Resources