Forum Discussion

jeffshurtliff's avatar
5 years ago

Is it possible to clear user cache for another user via FreeMarker?

Does anyone know if it is possible to clear/update the usercache (for a specific key) for another user, such as with the restadmin directive, via a macro or endpoint?

Or can user cache only be updated by the actual user?

For example, I have the key userInfo in user cache for our users which is a FreeMarker hash, so I am hoping to have a custom macro or endpoint where administrators can manually "clear" the key by essentially running usercache.put("userInfo",{}) on behalf of that user.

Thanks!

  • It is not possible to get/set values in the user cache for a different user.

    Just off the top of my head, if you want to manage a per-user cache and be able to change values for different users, you could alternatively create app cache entries that have a user id as part of the key. By default you could do something like this:

    ${appcache.put(user.id + ":" + "userInfo", {})}

    You'll also have to change any logic that gets "userInfo" from the user cache to get it from the app cache with your new key format:

    ${appcache.get(user.id + ":" + "userInfo")}

    Then if you want to set it for the user with id 5 you could just include that id in the key:

    ${appcache.put("5:userInfo", {})}

    If you do this, it will be up to you to ensure that the right content is shown to the right users (whereas the user cache kind of does that for you). 

    Also if you do this, you might want to file a support case requesting to double the size of your app cache (since you will now be putting all the entries you used to put in your user cache in your app cache).


     -Doug

3 Replies

  • DougS's avatar
    DougS
    Khoros Oracle
    5 years ago

    It is not possible to get/set values in the user cache for a different user.

    Just off the top of my head, if you want to manage a per-user cache and be able to change values for different users, you could alternatively create app cache entries that have a user id as part of the key. By default you could do something like this:

    ${appcache.put(user.id + ":" + "userInfo", {})}

    You'll also have to change any logic that gets "userInfo" from the user cache to get it from the app cache with your new key format:

    ${appcache.get(user.id + ":" + "userInfo")}

    Then if you want to set it for the user with id 5 you could just include that id in the key:

    ${appcache.put("5:userInfo", {})}

    If you do this, it will be up to you to ensure that the right content is shown to the right users (whereas the user cache kind of does that for you). 

    Also if you do this, you might want to file a support case requesting to double the size of your app cache (since you will now be putting all the entries you used to put in your user cache in your app cache).


     -Doug

  • TedV's avatar
    TedV
    Khoros Alumni (Retired)
    5 years ago

    Hi jeffshurtliff

     

    If you found the answer to be satisfactory, would you mind marking it as an accepted solution?

     

    Thanks!