Is there a way to run custom code on Azure Cache expiration? (where last cached value is accessible) - azure

What I mean is a kind of event or callback which is called when some cached value is expiring. Supposedly this callback should be given the currenlty cached value, for example, to store it somewhere else apart from caching.
To find such a way, I have reviewed Notifications option, but they look like they are applicable for explicit actions with cache like adding or removing, whereas expiration is a kind of thing that occurs implicitly. I found out that none of these callbacks is not called many minutes after cache value has expired and has become null, while it is called normally within polling interval if I call DataCache.Remove explicitly (wrong, see update below).
I find this behavior strange as ASP.Net has such callback. You can even find an explanation how to utilize it here on SO.
Also, I tried DataCache Events. It is writtent in MSDN that literally
This API supports the .NET Framework infrastructure and is not intended to be used directly from your code.
Nevertheless I created a handler for these event to see if I can test its args like CacheOperationStartedEventArgs.OperationType == CacheOperationType.ClearCache but it seemed to be in vain.
At the moment, I started to think about workarounds of this issue of the lack of required callback. So suggestions how to implement them are welcome too.
UPDATE. After more attentive and patient testing I found out that notification with DataCacheOperations.ReplaceItem is sent after expiration. Regrettably, I did not find the way to get the value that was cached before the expiration had occurred.

Related

nodejs - how to keep checking if the jwt token is still valid

When you are inactive for a period of time in aws, aws will log you out and show pop-up like this.
I am wondering how aws handles it and how should do it in nodejs
Take a look this article. It may give a solution for you.
https://medium.com/tinyso/how-to-detect-inactive-user-to-auto-logout-by-using-idle-timeout-in-javascript-react-angular-and-b6279663acf2
When we hear about the timeout, I’m pretty sure that you will think about using setTimeout method in this context. And yes, it’s the simplest way to implement the timeout on the browser by the following steps:
Call setTimeout(, )
If users do something on the app (move, click, input), we clear the timeout by using clearTimeout method and then call setTimeout again. However, this solution is just working fine if the users are on a single tab. If they are using our app on multiple tabs, it should be an issue since they are active on the current tab but inactive on the rest. Then we need to find another solution that allows the active state to sync across multiple tabs
There are two ways to handle sessions in NodeJS.
Session based
Token based
Since you are asking about tokens, you can set expiry time for the created token.

Prometheus-net : callback to update a gauge when /metrics endpoint is called?

I'm not sure I got correctly how prometheus-net should be used but having a gauge that is time related I'd need to be able to update its value when data is being requested via the /metrics endpoint. I thought I might use a timer to updated the gauge but the ideal thing would be to have a callback exposed by prometheus-net to update what need updating just before data is returned.
If anyone needs it, prometheus-net provides the AddBeforeCollectCallback callback for collecting or updating your metrics, gauges, etc. just before Prometheus collects data from you.
From prometheus-net documentation
In some scenarios you may want to only collect data when it is requested by Prometheus. To easily implement this scenario prometheus-net enables you to register a callback before every collection occurs. Register your callback using Metrics.DefaultRegistry.AddBeforeCollectCallback().

ArangoDb: Time from save() to availability through AQL - waitForSync?

In my NodeJS backed REST API, using the ArangoJS library, I'm calling the await save(...) on a document in a collection. Note I'm not using using the waitForSync option.
Right after the await on the save, I'll send a SSE event to the client, which then immediately calls another REST API method, which uses AQL to query the very same collection. Unfortunately I get the previous (old/unchanged) data back. Waiting a sec then AQL-querying gives me the fresh data though.
Is waitForSync the solution? Most documentation states that this option waits for data to sync to the disk, but as I understand ArangoDB keep most data in memory, so it shouldn't affect the following query, which should query against memory?
Anyone care to explain?
Update
see my own answer
Just to mark this as answered:
As expected, there is nothing wrong with ArangoDb. Thanks to the comment/confirmation that await should be enough, I investigated further around my setup. Found that the problem was with caching, and adding a Cache-Control header with 'no-cache' resolved the issue.
Funny thing is that when developer console was open in Chrome, I never had problems. Found that the checkbox 'disable cache' in development mode had hidden the issue during development. Issue being a lot of 304 Not Changed responses.

Modifying content delivered by node-http-proxy

Due to some limitations about the web services I am proxying, I have to inject some JS code so that it allows the iframe to access the parent window and perform some actions.
I have built a proxy system with node-http-proxy which works pretty nicely. However I have spent unmeasurable hours trying to modify the content (on my own, using harmon as well, etc) that is being sent to the user without any success. I have found some articles and even some questions here but all of them are outdated and are not useful anymore.
I was wondering if someone can give me an actual example about how to do this, because I am unable to do it and maybe it is just that it is impossible to do at this point?
I haven't tried harmon, but I did try cheerio and it works.
However, I used http-mitm-proxy and not node-http-proxy.
If you are using http-mitm-proxy, you need to return a promise in the response handler. Otherwise, the proxy continues to send the original response without picking up your changes.
I have recently written another proxy at:
https://github.com/noeltimothy/noelsproxy
I'm going to add response handling to this soon. This one uses a callback mechanism, which means it wont return the response until the caller signals it to.
You should be able to use 'cheerio' and alter the content in JQuery style.

Trouble making a request to an API after the last 'session/end'

I'm currently working on a custom reporter that sends test results to Sauce Labs. The current version of the reporter can be found here.
The problem with it is that it doesn't send the data after the last session. For instance, if I have 2 browsers to test on, it will only send the results for the first browser tested, stopping before sending the second one.
The request is made at the 'session/end' topic from the ones available. From what I can tell the entire thing stops before the last request is made.
I made a more isolated custom reporter to show off the problem using setTimeout() instead of a request. See it here.
Thanks!
The Intern process exits explicitly immediately after all sessions are complete (after /runner/end is published), so an asynchronous operation like that is unlikely to have enough time to complete successfully.
Intern 1.2 will contain an improvement so it will wait until any outstanding operations complete, and this will work as you expect it to.

Resources