Why Glav Web Cache does not have the data I saved when called from other instance?
I've tried searching for my problems but nothing seems to ask what I wanted to ask.
I'm working on a web service that generates and sends a kind of token from server to client, currently I'm using Glav CacheAdapter (the web cache kind)
When someone requested a data call, the server should generate a token then saves it to a cache, then sends the key to the client, the client then should send the same token to the server and it should be checked with the one in the cache, but somehow when the server generates the key it successfully creates and saves one (I tested when debugging), but when the client call sends the token (it is the same one) but somehow the cache does not contain any data.
>>>> Project A
>> Service
public string Generate()
{
AppServices.Cache.InnerCache.Add($"AuthenticationTokenCache:{xxx}", DateTime.Now.AddDays(1), new StringValue() { Value = xxx });
return key;
}
public bool Validate(string token)
{
return AppServices.Cache.InnerCache.Get<StringValue>($"AuthenticationTokenCache:{xxx}") != null;
}
>> WebAPI
public bool CallValidate(string token)
{
var xService = new Service();
return xService.Validate(token);
}
>>>> Project B
>> WebAPI
protected override bool RequestValidation(string token)
{
var client = new HttpClient();
var authURL = $"/api/CallValidate?token={token}";
var response = client.GetAsync(authURL).Result.Content;
string jsonContent = response.ReadAsStringAsync().Result;
var authResult = JsonConvert.DeserializeObject<bool>(jsonContent);
if(authResult)
{
return true;
}
}
Is the cache type I use wrong, or maybe there's something wrong that I don't realize is wrong?
And when I create new instance of the same class does the cache gets shared between those object or not?
I'm not really sure as to how the details of how caching works, any pointer as to reference reading material would be helpful too.
Thank you.
c# asp.net-mvc web-services caching
|
show 1 more comment
I've tried searching for my problems but nothing seems to ask what I wanted to ask.
I'm working on a web service that generates and sends a kind of token from server to client, currently I'm using Glav CacheAdapter (the web cache kind)
When someone requested a data call, the server should generate a token then saves it to a cache, then sends the key to the client, the client then should send the same token to the server and it should be checked with the one in the cache, but somehow when the server generates the key it successfully creates and saves one (I tested when debugging), but when the client call sends the token (it is the same one) but somehow the cache does not contain any data.
>>>> Project A
>> Service
public string Generate()
{
AppServices.Cache.InnerCache.Add($"AuthenticationTokenCache:{xxx}", DateTime.Now.AddDays(1), new StringValue() { Value = xxx });
return key;
}
public bool Validate(string token)
{
return AppServices.Cache.InnerCache.Get<StringValue>($"AuthenticationTokenCache:{xxx}") != null;
}
>> WebAPI
public bool CallValidate(string token)
{
var xService = new Service();
return xService.Validate(token);
}
>>>> Project B
>> WebAPI
protected override bool RequestValidation(string token)
{
var client = new HttpClient();
var authURL = $"/api/CallValidate?token={token}";
var response = client.GetAsync(authURL).Result.Content;
string jsonContent = response.ReadAsStringAsync().Result;
var authResult = JsonConvert.DeserializeObject<bool>(jsonContent);
if(authResult)
{
return true;
}
}
Is the cache type I use wrong, or maybe there's something wrong that I don't realize is wrong?
And when I create new instance of the same class does the cache gets shared between those object or not?
I'm not really sure as to how the details of how caching works, any pointer as to reference reading material would be helpful too.
Thank you.
c# asp.net-mvc web-services caching
nuget.org/packages/Glav.CacheAdapter is what you are using?
– mjwills
Nov 22 '18 at 3:37
@mjwills yes that one
– encryptoferia
Nov 22 '18 at 3:39
Do you have multiple servers serving the web requests of generating and validating the token? If you are using WebCache, then it is clear that the token stored on cache of one server won't be available if the validate request goes to the other server. The solution for this is to use some common cache store such a memached, redis etc.
– Chetan Ranpariya
Nov 22 '18 at 4:07
@ChetanRanpariya That's what I'm afraid too, but from what I understand, the generate and validate function should be in one server, albeit when validating the web service object created one new instance of the class that has the generate and validate function.
– encryptoferia
Nov 22 '18 at 4:18
The instance of the object does have little impact here. For things to work fine you need to get the token value back from the Cache. So unless you fix the token store issue, you are kind of stuck.
– Chetan Ranpariya
Nov 22 '18 at 4:22
|
show 1 more comment
I've tried searching for my problems but nothing seems to ask what I wanted to ask.
I'm working on a web service that generates and sends a kind of token from server to client, currently I'm using Glav CacheAdapter (the web cache kind)
When someone requested a data call, the server should generate a token then saves it to a cache, then sends the key to the client, the client then should send the same token to the server and it should be checked with the one in the cache, but somehow when the server generates the key it successfully creates and saves one (I tested when debugging), but when the client call sends the token (it is the same one) but somehow the cache does not contain any data.
>>>> Project A
>> Service
public string Generate()
{
AppServices.Cache.InnerCache.Add($"AuthenticationTokenCache:{xxx}", DateTime.Now.AddDays(1), new StringValue() { Value = xxx });
return key;
}
public bool Validate(string token)
{
return AppServices.Cache.InnerCache.Get<StringValue>($"AuthenticationTokenCache:{xxx}") != null;
}
>> WebAPI
public bool CallValidate(string token)
{
var xService = new Service();
return xService.Validate(token);
}
>>>> Project B
>> WebAPI
protected override bool RequestValidation(string token)
{
var client = new HttpClient();
var authURL = $"/api/CallValidate?token={token}";
var response = client.GetAsync(authURL).Result.Content;
string jsonContent = response.ReadAsStringAsync().Result;
var authResult = JsonConvert.DeserializeObject<bool>(jsonContent);
if(authResult)
{
return true;
}
}
Is the cache type I use wrong, or maybe there's something wrong that I don't realize is wrong?
And when I create new instance of the same class does the cache gets shared between those object or not?
I'm not really sure as to how the details of how caching works, any pointer as to reference reading material would be helpful too.
Thank you.
c# asp.net-mvc web-services caching
I've tried searching for my problems but nothing seems to ask what I wanted to ask.
I'm working on a web service that generates and sends a kind of token from server to client, currently I'm using Glav CacheAdapter (the web cache kind)
When someone requested a data call, the server should generate a token then saves it to a cache, then sends the key to the client, the client then should send the same token to the server and it should be checked with the one in the cache, but somehow when the server generates the key it successfully creates and saves one (I tested when debugging), but when the client call sends the token (it is the same one) but somehow the cache does not contain any data.
>>>> Project A
>> Service
public string Generate()
{
AppServices.Cache.InnerCache.Add($"AuthenticationTokenCache:{xxx}", DateTime.Now.AddDays(1), new StringValue() { Value = xxx });
return key;
}
public bool Validate(string token)
{
return AppServices.Cache.InnerCache.Get<StringValue>($"AuthenticationTokenCache:{xxx}") != null;
}
>> WebAPI
public bool CallValidate(string token)
{
var xService = new Service();
return xService.Validate(token);
}
>>>> Project B
>> WebAPI
protected override bool RequestValidation(string token)
{
var client = new HttpClient();
var authURL = $"/api/CallValidate?token={token}";
var response = client.GetAsync(authURL).Result.Content;
string jsonContent = response.ReadAsStringAsync().Result;
var authResult = JsonConvert.DeserializeObject<bool>(jsonContent);
if(authResult)
{
return true;
}
}
Is the cache type I use wrong, or maybe there's something wrong that I don't realize is wrong?
And when I create new instance of the same class does the cache gets shared between those object or not?
I'm not really sure as to how the details of how caching works, any pointer as to reference reading material would be helpful too.
Thank you.
c# asp.net-mvc web-services caching
c# asp.net-mvc web-services caching
asked Nov 22 '18 at 3:29


encryptoferiaencryptoferia
897
897
nuget.org/packages/Glav.CacheAdapter is what you are using?
– mjwills
Nov 22 '18 at 3:37
@mjwills yes that one
– encryptoferia
Nov 22 '18 at 3:39
Do you have multiple servers serving the web requests of generating and validating the token? If you are using WebCache, then it is clear that the token stored on cache of one server won't be available if the validate request goes to the other server. The solution for this is to use some common cache store such a memached, redis etc.
– Chetan Ranpariya
Nov 22 '18 at 4:07
@ChetanRanpariya That's what I'm afraid too, but from what I understand, the generate and validate function should be in one server, albeit when validating the web service object created one new instance of the class that has the generate and validate function.
– encryptoferia
Nov 22 '18 at 4:18
The instance of the object does have little impact here. For things to work fine you need to get the token value back from the Cache. So unless you fix the token store issue, you are kind of stuck.
– Chetan Ranpariya
Nov 22 '18 at 4:22
|
show 1 more comment
nuget.org/packages/Glav.CacheAdapter is what you are using?
– mjwills
Nov 22 '18 at 3:37
@mjwills yes that one
– encryptoferia
Nov 22 '18 at 3:39
Do you have multiple servers serving the web requests of generating and validating the token? If you are using WebCache, then it is clear that the token stored on cache of one server won't be available if the validate request goes to the other server. The solution for this is to use some common cache store such a memached, redis etc.
– Chetan Ranpariya
Nov 22 '18 at 4:07
@ChetanRanpariya That's what I'm afraid too, but from what I understand, the generate and validate function should be in one server, albeit when validating the web service object created one new instance of the class that has the generate and validate function.
– encryptoferia
Nov 22 '18 at 4:18
The instance of the object does have little impact here. For things to work fine you need to get the token value back from the Cache. So unless you fix the token store issue, you are kind of stuck.
– Chetan Ranpariya
Nov 22 '18 at 4:22
nuget.org/packages/Glav.CacheAdapter is what you are using?
– mjwills
Nov 22 '18 at 3:37
nuget.org/packages/Glav.CacheAdapter is what you are using?
– mjwills
Nov 22 '18 at 3:37
@mjwills yes that one
– encryptoferia
Nov 22 '18 at 3:39
@mjwills yes that one
– encryptoferia
Nov 22 '18 at 3:39
Do you have multiple servers serving the web requests of generating and validating the token? If you are using WebCache, then it is clear that the token stored on cache of one server won't be available if the validate request goes to the other server. The solution for this is to use some common cache store such a memached, redis etc.
– Chetan Ranpariya
Nov 22 '18 at 4:07
Do you have multiple servers serving the web requests of generating and validating the token? If you are using WebCache, then it is clear that the token stored on cache of one server won't be available if the validate request goes to the other server. The solution for this is to use some common cache store such a memached, redis etc.
– Chetan Ranpariya
Nov 22 '18 at 4:07
@ChetanRanpariya That's what I'm afraid too, but from what I understand, the generate and validate function should be in one server, albeit when validating the web service object created one new instance of the class that has the generate and validate function.
– encryptoferia
Nov 22 '18 at 4:18
@ChetanRanpariya That's what I'm afraid too, but from what I understand, the generate and validate function should be in one server, albeit when validating the web service object created one new instance of the class that has the generate and validate function.
– encryptoferia
Nov 22 '18 at 4:18
The instance of the object does have little impact here. For things to work fine you need to get the token value back from the Cache. So unless you fix the token store issue, you are kind of stuck.
– Chetan Ranpariya
Nov 22 '18 at 4:22
The instance of the object does have little impact here. For things to work fine you need to get the token value back from the Cache. So unless you fix the token store issue, you are kind of stuck.
– Chetan Ranpariya
Nov 22 '18 at 4:22
|
show 1 more comment
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53423460%2fwhy-glav-web-cache-does-not-have-the-data-i-saved-when-called-from-other-instanc%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53423460%2fwhy-glav-web-cache-does-not-have-the-data-i-saved-when-called-from-other-instanc%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
nuget.org/packages/Glav.CacheAdapter is what you are using?
– mjwills
Nov 22 '18 at 3:37
@mjwills yes that one
– encryptoferia
Nov 22 '18 at 3:39
Do you have multiple servers serving the web requests of generating and validating the token? If you are using WebCache, then it is clear that the token stored on cache of one server won't be available if the validate request goes to the other server. The solution for this is to use some common cache store such a memached, redis etc.
– Chetan Ranpariya
Nov 22 '18 at 4:07
@ChetanRanpariya That's what I'm afraid too, but from what I understand, the generate and validate function should be in one server, albeit when validating the web service object created one new instance of the class that has the generate and validate function.
– encryptoferia
Nov 22 '18 at 4:18
The instance of the object does have little impact here. For things to work fine you need to get the token value back from the Cache. So unless you fix the token store issue, you are kind of stuck.
– Chetan Ranpariya
Nov 22 '18 at 4:22