How to get all cache keys in Serenity-Platform? - caching

I want to develop a page where all the cache lists will show and the user can clear a cache by clicking a button.
But I am facing a problem to get all the cache keys which have been set.

Serenity doesn't needs cache keys as list. So there is no way to retrieve keys from serenity cache classes.
If you need to retrieve keys, you can create new classes what implement IDistributedCache and/or ILocalCache. Then register this classes from startup.cs. Also don't forget to remove serenity code from there
And before you register your own cache implementation, don't forget to add services.AddMemoryCache(); for memory cache implementation if you use.
Then you can get your implementation everywhere like code below. StaticProvider property is resolves registered classes for you.
(LocalCache.StaticProvider as MyCustomLocalCacheProvider).GetAllKeys();
(DistributedCache.StaticProvider as MyCustomDistributedCacheProvider).GetAllKeys();

Related

Clear the Cache Scope and Private object store in Mule 4

I am building the application in Mule 4 to cache the response from http request component (for 1 hours). I use the response to validate the jwt. Whenever there is a failure, I need to clear the cache and re-invoke the http request. Component used is : Cache Scope
My Current Code looks like below:-
<ee:object-store-caching-strategy name="Caching_Strategy" doc:name="Caching Strategy" doc:id="50e44473-b55a-4bc3-b53a-18e4229a31a3" keyGenerationExpression="#['token']" >
<os:private-object-store persistent="false" maxEntries="${caching.maxEntries}" entryTtl="${caching.entryTtl}" expirationInterval="${caching.expirationInterval}" />
</ee:object-store-caching-strategy>
I don't have any specific requirement to make it private object store but disabling it does not allow me to configure the maxEntries, entryTTL and Expiration Interval.
It would be more helpful if you could guide me the ways to
clear the cache (could not find any docs mule 4 related to clear the cache)
how can i keep it as non private object store and define those parameters like entryTtl, maxEntries etc.
when do we need to use the private object stores?
I have already tried the exchanges examples for configure the cache ( but there is no mention of clear the cache).
I am using Mule Runtime 4.2.2 and On Prem Mule
I have raised a support ticket with Mulesoft and received the below replies
1) Invalidate Cache is shown only in the palette from the Anypoint Studio Version 7.4.1. Not shown in earlier version of studio.( I was using 7.3.2)
2) They are adding the documentation for the invalidate cache in Mule 4.
3) Usage Note : Cache Scope and the 'Invalidate Cache' processor should share the same Caching_Strategy).
4) In order to explicitly define object store and ttl for a Cache Scope, please ensure object store related modules are added to the project.
This can be done by simply adding a 'Store' processor in your mule flow, this will add all necessary modules to your mule application.
Then, on the Caching Strategy, General > Reference > Object Store, you can select Edit Inline and define your object store with explicit settings such as
- Max entries
- Entry ttl
- Expiration interval
You can remove the unused 'Store' processor as well.
Hope it helps others
There is a palette called invalidate cache in the latest Mule versions. You can simply use it to delete the cache for a cache scope.
You will require a private object store when you want to persist the key used for caching permanently and also to implement time limits like TTL for a cache.

aspnetboilerplate session timeout & redis implementation

I am using ABP framework with MVC 5 and deployed into Azure. I have listed few session related questions below.
I used HttpContext.Current.Session in WebMpa project and AbpSession in Application services, but unable to get the data from AbpSession using HttpContext.Current.Session in WebMpa project, both are saving data in different place?
Am using static helper class and static property to Get/Set HttpContext.Current.Session value, if i want to remove the HttpContext.Current.Session any easiest way is available(with minimal code change), it could be better if we can get AbpSession from that static class?
I want to alert users 20 secs prior to session expired, is there any build in option available in ABP?
If I enable to Redis Cache implementation in my application, Cache, HttpContext.Current.Session, AbpSession and TempData will works without any issues and all should Get/Set values from Redis datasource?
AbpSession is not extending HttpContext.Current.Session. So the answer is yes you cannot share data btw AbpSession and Session.
Don't use static for injectable types. bad practise!
There's no built-in function for that. You can achieve this with a javascript function. When you finish a request, start timer. You know the session timeout duration. So when it reaches to 20secs, show an alert window to continue session. If answer is Yes then make a new request to slide session.
No! As i stated, Session and AbpSession is totally different things and you cannot share btw them.
PS: AbpSession stores claims. And it's extendable. So you can store any item in AbpSession. See the link to understand how to extend AbpSession https://gist.github.com/hikalkan/67469e05475c2d18cb88

Persist a Spring Java Object into Magnolia repository

If i had an additional Spring application extending my Magnolia, which gets some Java Object, which will be used inside my application, how can i save it ???
I already learned to do queries, but i cannot use it yet to put something in or change it. I can only fetch data. into nodes.
where or how do i persist ??
For Info: I have a repository which shall store the special data and i have a nodetype declared for this. As it is now the spring social UserConnection i have the workspace "connections" with nodeType mgnl:userConnection
My JavaObject is a UserConnection, designed near to MgnlUser, so i also add properties, but i don't know yet, what to do with path and uuid.
i don't know yet how to declare it or where to get it.
You can store the data same way as you fetch it. Assuming you are running your spring app through Magnolia filter chain you have MgnlContext setup for given thread and can easily call MgnlContext.getJCRSession("connections") to obtain the session and node same way you do to retrieve your data, to add subnodes or set properties on given node you just call node.addNode("myNewNode") or node.setProperty("myProp", "newValue") on the node and follow that with call to session.save() to persist the session info. But I guess you already know all that.
If you want to get whole object serialised into repo for you by system instead, you can use JackRabbit OCM for this, or even easier - use integration of OCM into Magnolia - http://jira.magnolia-cms.com/browse/MJROCM
. It's already used in Shop module of Magnolia if you are looking for examples on how to work with OCM.
HTH,
Jan

Grails store and fetch data on client side

Background: We are using grails 2.1.1. We are not using any DB as of now. We make a web service call for each response on another server.
Now the problem is, there is web service call which returns some static data in XML form and this data is usable throughout the application. The size of the xml is around 40kb. This xml contains static data like, project_list, status_type_list etc. and we have to use this in various dropdowns and menu items in different gsp pages.
So, please suggest us the best way to handle this data. So that it doesn't effect our page load time and browsing experience. And also we can easily use the data on client side.
responding to your comment on the question. I would prefer using annotation based caching over the plugin, if the requirement is as simple as you state that it is.
If the calls are being made from server-side and you want to cache the results of the parsed XML then you can do something like:
#Cacheable("staticDataCache")
def getStaticDataFromXML() {}
You can then use the above method to pull the maps, lists whatever data structure you've used to store the result and it will pull it from the cache.
and then another service method to flush the cache, which you can call frequently from a Job.
#CacheFlush("staticDataCache")
def flushStaticDataCache() {}
Use the cache plugin to cache the static xml data. And then add some policy as to when the cache should be updated... (i.e. using a job to check if the xml has changed every hour)

AppFabric Server cache returns dll object with null values

I'm new with AppFabric Server caching but after playing around with it everything has been working like a dream.
I can add for example datatables to my cache and get that back to use just fine.
I got exited about this functionality and tried to test this with one 3rd party vendors dll that includes login session data (session id, date's etc.)
I created WCF service with method where you consume this dll to login and I store that session to my cache.
This works just fine and I can verify this by looking at statistics of my cache with PowerShell.
Then I created another method that is supposed to pick up this cached session and use it to execute actions. This is where I'm running to the wall.
I can see that I have been able to get session from cache, but information within session object is null (session id, date's...)
I've been serching help for this from everywhere but nobody seams to face this issue.
So my question is
Can AppFabric server cache ALL field values of given object (Public/Non-public not having any role)?
Is there any way to see actual existing content of cache where you would see keys and cached objects with values?
Thanks for all possible comments!
Regards
Mikko
In AppFabric you can only cache objects that are serialisable (or serializable for US readers :-) ). The fact that you have been able to store your session objects in the cache suggests that they are indeed serialisable. But to figure out what's going on here we'll need to probe a little deeper.
By default with binary serialisation, all fields/properties of an object are serialised, public and private (whereas XML serialisation only picks up the public values). We aren't told which flavour of serialisation AppFabric uses, but binary serialisation tends to be more efficient so it's a reasonable assumption that that's what gets used under the covers. However, it's possible to override the serialisation behaviour using the NonSerialized attribute, so that items marked NonSerialized don't make it into the serialised version of the object. The MSDN page for Selective Serialisation specifically advises that security-sensitive information should be marked as nonserializable.
A session ID definitely comes under the heading of security-sensitive information as it's key for session hijacking, so I should say that's the problem you're facing. You could confirm this by having a look inside the 3rd party DLL with ILDasm or Reflector to see if the fields inside the session class are indeed marked as not serialised.
Can you get round this? Well there is, of course, nothing to stop you creating your own Session class that you populate from the 3rd party's object where you keep all the properties serialisable and caching that instead. Bear in mind, however, that you're then essentially doing the very thing they've tried to stop you doing...

Resources