Developer forum

Forum » Dynamicweb 10 » Custom services caches not shown

Custom services caches not shown

Anders Ebdrup
Reply

Hi DW,

 

We experience at least on this version: 10.17.8, that our custom services are not shown in the list below, but they are shown in our local development environments. Our tricks to make them work in the cloud environment as well?

Best regards, Anders


Replies

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply

Can you show us your service code?

 
Anders Ebdrup
Reply

Yes, of course. This is the code that is working local, but not in the cloud:

 

 public class CustomFacetCacheService : ICacheStorage<string, object>
 {
     private static readonly Lazy<CustomFacetCacheService> _instance = new(() => new CustomFacetCacheService());
     public static CustomFacetCacheService Instance => _instance.Value;

     private static ServiceCache<string, object> ServiceCacheStorage { get; set; }
     CacheInformation ICacheStorage.Info => ServiceCacheStorage.Info;

     static CustomFacetCacheService()
     {
         ServiceCacheStorage = new DictionaryCache<string, object>(typeof(CustomFacetCacheService))
         {
             InitializeCache = InitializeCache,
             FetchOnNotFound = UpdateCache,
             RefreshOnClear = UpdateCache
         };
     }

     private static Dictionary<string, object> InitializeCache()
     {
         return [];
     }

     private static Dictionary<string, object> UpdateCache(IEnumerable<string>? ids)
     {
         ids = ids?.Where(key => key is not null).Distinct(StringComparer.OrdinalIgnoreCase);
         if ((ids?.Any()) != true == true)
         {
             return [];
         }

         return [];
     }

     public object? Get(string key)
     {
         var value = ServiceCacheStorage.GetCache(key);
         return ServiceCacheStorage.GetCache(key);
     }

     public void SetCache(string key, object value)
     {
         ServiceCacheStorage.SetCache(key, value);
     }

     public void ClearCache()
     {
         ServiceCacheStorage.ClearCache();
     }

     public void SetCacheType<TObjectCache>() where TObjectCache : ServiceCache<string, object>
     {
     }

     public void ClearCache(IEnumerable<string> keys)
     {
         ServiceCacheStorage.ClearCache(keys);
     }

     public void ClearCache(string key)
     {
         ServiceCacheStorage.ClearCache(key);
     }
 }

 
Kristian Elmholt Kjær Dynamicweb Employee
Kristian Elmholt Kjær
Reply

Hi Anders,

 

How do you install the assembly with this new "CustomFacetCacheService"? Via nuget?

 

And if so, have you tried recycling the site to see if this makes it show up?

 

/Kristian

 
Anders Ebdrup
Reply

Hi Kristian,

 

Thanks for looking into it.

We install the assemblies through the CLI, and we have tried to recycle the application afterwards.

The CLI command is: dw install "$nupkg" --host ${{ parameters.hostUrl }} --apiKey ${{ parameters.apiKey }}

 

Best regards, Anders

 
Anders Ebdrup
Reply

Hi Kristian,

 

Did you have a change to look into this issue?

 

Best regards, Anders

 
Kristian Elmholt Kjær Dynamicweb Employee
Kristian Elmholt Kjær
Reply

Hi Anders,

 

Sorry the delayed response. The code example you've posted in here - is that some "dummy" code, or is it intentional that you implement "ICacheStorage<string, object>" (specifically empasizing "object" as the generic "TCachedObject" argument?

If not, could you please post a more correct example?

 
Anders Ebdrup
Reply

Hi Kristian,

 

We are using it to cache various types, and thats why we use "object" as the generic "TCachedObject" argument. And at the same time we need to be able to clear this cache from the administration and also clear the cache when running a data integration job.

 

Best regards, Anders

 
Kristian Elmholt Kjær Dynamicweb Employee
Kristian Elmholt Kjær
Reply

Hi Anders,

 

I can't rule out that using "object" as argument could cause some issues - though I'm uncertain at this point.

However, I would strongly suggest using a unique "TCachedObject" key, that won't potentially clash with existing internal service implementations.

I think that is what I can suggest for now, but I'm curious to see if it will resolve the issue. If not, don't hesitate to contact us again.

 

/Kristian

 
Anders Ebdrup
Reply

Hi Kristian,

 

Thanks for the feedback. I will give it a try, but what is the different between running it local and in the cloud? Because it works if I download the dll from the cloud and put it into my bin-folder. Can you try the same?

 

Best regards, Anders

 
Kristian Elmholt Kjær Dynamicweb Employee
Kristian Elmholt Kjær
Reply

Hi Anders.

Could upload the "TypeLoadErrors.log" from "Files/System/Log/AddInManager" from the cloud site to this thread? Then I could take a look if there's any load errors that might indicate something.

 
Anders Ebdrup
Reply

Dear Kristian,

 

You can find the file here: https://avn.dw10staging.dynamicweb-cms.com/Admin/UI/Files/ContentFileEdit/e626e98b4d434e9c906dafef28f0da1c?FilePath=%2FFiles%2FSystem%2FLog%2FAddInManager%2FTypeLoadErrors.log&Type=ContentFileByName. And this is now my file: 

 

 public class CustomFacetCacheService : ICacheStorage<string, CustomFacetCacheItem>
 {
     private static readonly Lazy<CustomFacetCacheService> _instance = new(() => new CustomFacetCacheService());
     public static CustomFacetCacheService Instance => _instance.Value;

     private static ServiceCache<string, CustomFacetCacheItem> ServiceCacheStorage { get; set; }
     CacheInformation ICacheStorage.Info => ServiceCacheStorage.Info;

     static CustomFacetCacheService()
     {
         ServiceCacheStorage = new DictionaryCache<string, CustomFacetCacheItem>(typeof(CustomFacetCacheService))
         {
             InitializeCache = InitializeCache,
             FetchOnNotFound = UpdateCache,
             RefreshOnClear = UpdateCache
         };
     }

     private static Dictionary<string, CustomFacetCacheItem> InitializeCache()
     {
         return [];
     }

     private static Dictionary<string, CustomFacetCacheItem> UpdateCache(IEnumerable<string>? ids)
     {
         ids = ids?.Where(key => key is not null).Distinct(System.StringComparer.OrdinalIgnoreCase);
         if ((ids?.Any()) != true == true)
         {
             return [];
         }

         return [];
     }

     public CustomFacetCacheItem? Get(string key)
     {
         var value = ServiceCacheStorage.GetCache(key);
         return value;
     }

     public void SetCache(string key, CustomFacetCacheItem value)
     {
         ServiceCacheStorage.SetCache(key, value);
     }

     public void ClearCache()
     {
         ServiceCacheStorage.ClearCache();
     }

     public void SetCacheType<TObjectCache>() where TObjectCache : ServiceCache<string, CustomFacetCacheItem>
     {
     }

     public void ClearCache(IEnumerable<string> keys)
     {
         ServiceCacheStorage.ClearCache(keys);
     }

     public void ClearCache(string key)
     {
         ServiceCacheStorage.ClearCache(key);
     }

Where the generic "object"-type now is changed, but still with no luck on the cloud-server, but I can still see the servicecache on my local development environment. But I cannot refresh the cache locally - see this dump from Visual Studio:


Best regards,

Anders

 
Kristian Elmholt Kjær Dynamicweb Employee
Kristian Elmholt Kjær
Reply

Hi Anders,

 

The custom dll (nuget package) you install - does that have all the neccessary dependencies co-deployed as well? Because our system (AddInManager) skips assemblies that cannot be loaded for some reason or the other, which would make sense that it doesn't discover your Custom Service from an assembly that might be missing one or more dependencies?

I've discussed this in the office today, and this was one of the ideas that came to our minds.

 

/Kristian

 
Anders Ebdrup
Reply

Hi Kristian,

 

The custom dll does not have any dependencies.

Can you try to put the dll into the bin-folder on the solution and see if it see registered?

 

Best regards Anders

 
Anders Ebdrup
Reply

Hi Kristian,

 

Just an input regarding the other thing that I have experienced regarding clearing caches in DW. Please see this screen dump, where it looks like DW tries to locate the cache storage in the wrong way. And compare it with my experiment with this line:            
var tmpServiceCache = DependencyResolver.Current.GetServices<ICacheStorage>().FirstOrDefault(cache => cache.Info.Owner == serviceType);


 

Best regards, Anders

 
Anders Ebdrup
Reply

Hi Kristian,

 

And just to clarify I can see my addin under these sections; Local, Notification Subscribers and Configurable Add Ins, and the caching is working, but I cannot see it and clear it under "Service caches" or under the "cache" section on the import jobs.

 

Hope that can help you to find the cause.

 

Best regards, Anders

 
Kristian Elmholt Kjær Dynamicweb Employee
Kristian Elmholt Kjær
Reply

Hi Anders,

I have found the issue and a solution to it. It was "merely" because we was loading the custom assemblies a little too early, which caused them to not be found for the "Service caches" list.

I have made a work item with the ID 25679, if you want to follow along.

Edit: and thanks for the thorough information along the way!

/Kristian

 
Anders Ebdrup
Reply

Thank you so much - sounds great! :-)

 

Did you also had a change to look into the issue with not being able to clear cache from the list with this button?

 
Kristian Elmholt Kjær Dynamicweb Employee
Kristian Elmholt Kjær
Reply

Yes, I tested both clearing directly from the Context menu in the list and from this action you mention :)

 
Anders Ebdrup
Reply

Excellent, so that was related to the same thing?

 
Kristian Elmholt Kjær Dynamicweb Employee
Kristian Elmholt Kjær
Reply
This post has been marked as an answer

Yes :-)

Votes for this answer: 1

 

You must be logged in to post in the forum