Base solution for your next web application
Starts in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

Redis Cache Implementation Question #1160


User avatar
0
maharatha created

Hi Hilkan -

I am trying to implement Redis Cache looking at the way you have implemented UserPermissionCache. Basically I will be storing a table data into the Cache let's say "AutofillData" The table has ID, Name, few more fields

I have named my Cache to be AutofillCache and plan to store with the following key and value

Key : TenantID:OrganizationID:Autofill

Value : Should I use HashSet to store the data or do you have any other recommendations ?

I need to also update the values when items are added or modified in the table.

Could you help me in accomplishing this ?


2 Answer(s)
  • User Avatar
    0
    hikalkan created
    Support Team

    You should combine some structures to accomplish it.

    1. Use CacheManager to create and use caches.
    2. Use EventBus events to detect entity changes and refresh your cache.

    Also, don't store Entities in the cache. Because, they are not well serializable and can not be stored in redis cache.

    Actually, after your question, I created a generic entity cache base class. You can use it to easily create caches. See my commit: <a class="postlink" href="https://github.com/aspnetboilerplate/aspnetboilerplate/commit/9aefef9506fcef16be1a34458cc0f02dfae6b73b">https://github.com/aspnetboilerplate/as ... 2dfae6b73b</a>

    EntityCache class and interfaces will be released in next version. Currently;

    1. Copy EntityCache and IEntityCache into your project.
    2. Create a YourEntityCache class like MessageCache here: <a class="postlink" href="https://github.com/aspnetboilerplate/aspnetboilerplate/commit/9aefef9506fcef16be1a34458cc0f02dfae6b73b#diff-95d7cffbfdc838d8ab1efb1f009fb9a3R45">https://github.com/aspnetboilerplate/as ... 09fb9a3R45</a> (IMessageCache is optional)
    3. Define a class to store cache items, like: <a class="postlink" href="https://github.com/aspnetboilerplate/aspnetboilerplate/commit/9aefef9506fcef16be1a34458cc0f02dfae6b73b#diff-95d7cffbfdc838d8ab1efb1f009fb9a3R60">https://github.com/aspnetboilerplate/as ... 09fb9a3R60</a>
    4. Inject your cache class wherever it's needed and use it.
  • User Avatar
    0
    maharatha created

    There is just one word that describe you :: Awesome !!!!