Redis returning "-1" for absent key while redirecting to slot. What could be the reason for this? - caching

clustercfg.application-cluster.wtdhdu.memorydb.eu-west-1.amazonaws.com:6379> KEYS count:followers:24c2b81c-17b4-443d-95b3-1c78cb4644d1
(empty array)
clustercfg.application-cluster.wtdhdu.memorydb.eu-west-1.amazonaws.com:6379> GET count:followers:24c2b81c-17b4-443d-95b3-1c78cb4644d1
-> Redirected to slot [15273] located at application-cluster-0002-002.application-cluster.wtdhdu.memorydb.eu-west-1.amazonaws.com:6379
"-1"
(1.16s)
Ideally redis should have made a database call and fetched the value from it but instead it returned -1.
I would like to ask under what circumstances does such a behavior occurs?

Related

Can I use StackExchange.Redis to store a Null value in Redis?

Is there any way to use the StackExchange.Redis client to store a Null value in Redis?
If you use IDatabase.StringGet(key) then the returning of Null is used to signify that there "was no result". Therefore if you use IDatabase.StringSet(key, null) then the result is you don't know whether there is a Null value or No value!
Is there any mechanism for catering for this? - i.e. you want to cache a negative.
I was rather hoping to avoid any nasty sentinel values (like value ?? new byte[] {1}) that could later cause issues if a value happened to match!
I had a look at RedisValue.Null but that just yields a Null which has the same issues as above.
This is usual dilemma with nulls. We had similar situations and here is how we dealt with them:
We retrieved list of dates from backend system and stored them in cache. DAL class returned null if no dates were retrieved and threw an exception in case of error/timeout communicating with backend system. In order to cache null value, we replaced null with empty list - which still signified that there was no date available.
We used to store users preference as a string in backend. A null value signified that user had not set preference. To cache this, we cached special string value that would never occur in the use case - something like NO PREFERENCE.
HTH.
I'm using a proxy pattern to reduce calls to the database. The only reasonable way I found was to store an empty byte array in Redis.
byte[] array = new byte[0];
IDatabase.StringSet(key, array)
When querying Redis you can use value.IsNull to check if byte array is empty or not.
This way seems preferable to storing 0, "" or any other arbitrary value.

How to check if a url path exists in the service worker cache

I need to check if a particular URL path exists in the service worker cache.
For example, suppose my URL is:
/myserviceworker/service?a=110&b=70
this URL exists in the cache, but there are many of them with different values of a and b.
Now, suppose I want to refresh all of these URLs, how can I do that?
I want to know how to access the key values from Service Worker cache.
If I know the key, my plan is as follows:
var url = new URL(key);
if(url.pathname === "\/myserviceworker/service")
then refetch the key
But I am not sure how to get the cache key and in what format it is. I mean, is it a string or is it already a URL?
Cache API has a match() method which returns a promise resolving in a Response object if match or undefined if no match exists. The second parameter is an object where you can specify ignoreSearch to not take into account URL parameters.
The ignoreSearch option is actually supported only by Firefox (Chrome status here).
In the other hand, to retrieve all the cache entries, you can use the keys() method.

Codeigniter session variable lose its value after ajax request

I have a problem, when I make a AJAX request to retrieve more data a session variable called is_logued which indicates is the current user is logged in the system lose its value.
I have test it with the rest of the page and it is ok, no problems. The problem comes when the ajax request is sent.
I have make a debug in the Session class, but I cannot find anything strange. I make a print_r to the values and the variable is correctly set inside the Session Class. Moreover the values are stored in the database in the CI_SESSIONS table.
Anyone knows what is happening? Is there any process that writes in the session table without using the Session library? It is very strange because only is_logued lose its value. I have check is I do it manually but does not. Nobody calls unset to that variable.
More information
public function load_next_links($param)
{
$this->load->helper('principal_helper');
echo "is_logued value ".$this->session->userdata("is_logued");
echo get_next_links($param);
echo "is_logued value ".$this->session->userdata("is_logued");
}
In both cases is_logued value has the correct value 1. This function is located in the principal controller. But after the call the database has the value 0. Why?
More data:
I have print the values in the database in the last line of the CodeIgniter.php (core) and the bbdd has the good value! why when I saw the database the value is not the correct? where is this value being changed?

Azure ACS + Form value storage

I'm using Azure ACS in my ASP.net MVC 3 website (hosted in Azure too), the scenario is this:
A user first enters my website and fills a one field form, then they need to chose a provider and login, but first I want to store the field value so when they come back from login I'm able to create a profile with this value for the loged in user.
So I believe when they first enter the site and then leaves to login and enters the site again those are two different sessions am I right? and that's the reason the stored data using session state (through SQL Server) is not present when they come back after login am I right? if this is true what would be the best approach then? if not then I'm doing something wrong storing temp data right?
Thanks
UPDATE:
I have discovered that HttpContext.Application state works keeping the data, still I'm not sure if it's a good idea to use it in a controller considering it's in Azure, will it work on production properly??
You can pass state around in the WS-Federation redirect sequence using the wctx URL parameter. In the action that handles the initial POST request, you should get hold of the form parameter you want to keep, then redirect to you identity provider selection page (this will have to be a custom page) with the form parameter appended to the URL. When the user selects an IP on your page, you can pass the parameter on again using the wctx parameter. The WS-Federation passive requestor profile says that this should be returned to you eventually when the IP redirects the user back to your site.
This has some details
http://msdn.microsoft.com/en-us/library/bb608217.aspx
Edit: To get the wctx parameter out of the request when the user finally comes back to your app. Put something like this in the action code:
var fam = FederatedAuthentication.WSFederationAuthenticationModule;
if (fam.CanReadSignInResponse(System.Web.HttpContext.Current.Request, true))
{
string wctxValue = this.HttpContext.Request.Form["wctx"];
}
My preference is to have the wcxt parameter represent a redirect URL (URL encoded) with your parameter as a query parameter in that so it be a URL encoded version of this:
wctx=https://yourserver/yourapp/yourpage?yourparameter=foo
Then the action that was receiving the redirect from the ACS would simply pull out the value of wctx and do a redirect to it without any more processing. This keeps things simple.
Another approach would be to save whatever data you need to pass around in the Database, and just pass around some ID that refers back to the database record. You'll pass this ID to IP and back through wctx (as Mike mentioned above).
This will solve the issue of limited length of URLs (in case your data is very large). Of course you would need to manage deletion of this data, but this shouldn't be hard.

How to prevent Alfresco webscript response caching

I have a webscript in alfresco that does something simple: reads a property, and based on its value, creates a json response. Another webscript is in charge of updating this property. However, the response from the original script is sometimes cached, and not for all clients.
So, for one client, I get a current status, and for the other I get the previous state.
The webscript basically reads a property from a node (nodeRef was sent in webscript request):
var status = doc.properties["my:customProp"];
switch (status) {
case "something":
model.prop = "FirstResponse";
break;
case "somethingElse":
model.prop = "SecondResponse";
break;
default:
model.prop = "ThirdResponse";
}
The freemarker template then parses the prop and creates a json output for the response.
Now, this should be simple and straightforward. The use case is as follows:
1. When a user #1 first gets to the doc, the status was set to "something". He got a "FirstResponse", and with a webscript he changed it.
When he then get the document again, he gets the second response.
But if a second client accesses this same node and asks for the response, it still gets the first response, and even more, when I try to read that prop, I get the "old" prop.
So I'm refreshing the script from two clients and reading this property, one client gets one value, the other gets another value.
My only guess (so far) is that this is a caching issue. So, how do I prevent caching? And where did it happen? Hibernate? Some sort of repository cache? How to get rid of it?
check http://wiki.alfresco.com/wiki/Web_Scripts#cache
Well, found the problem here, the prop was defined as d:mltext. So it wasn't cached information, just multilanguage info. I had to extend the model and add a new prop that multilanguage, now all users have the same information.

Resources