3

I use StackExchange.Redis to work with cache. I have action which returns values from cache (if value exists)

public ActionResult GetCalculatorSalaries()
    {
        var s = (string) _cache.StringGet("CalculatorSalaries");
        if (String.IsNullOrEmpty(s))
        {
            var salaries = _service.LoadCalculatorSalaries();
            _cache.SetAdd("CalculatorSalaries", (string)salaries);
            return Json(salaries, JsonRequestBehavior.AllowGet);
        }
        return Json(s, JsonRequestBehavior.AllowGet);
    }

_service.LoadCalculatorSalaries(); - this is service which returns data from Azure Blob and here returns data as string.

Problem: I set value for key "CalculatorSalaries" as string but when i try to get it, i get an error, as value by that key is of type set.

Where i am wrong?


P.S. When i debug code at step

var s = (string) _cache.StringGet("CalculatorSalaries");

debuging skiping when value exists for key "CalculatorSalaries" and error get only in browser console

1 Answer 1

5

You're calling SetAdd... thereby adding a set.

Perhaps you meant StringSet:

var salaries = _service.LoadCalculatorSalaries();
_cache.StringSet("CalculatorSalaries", (string)salaries);
//     ^^^^^^^^^ this
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.