Alachisoft / NCache

NCache: Highly Scalable Distributed Cache for .NET
http://www.alachisoft.com
Apache License 2.0
647 stars 123 forks source link

Possible to specify client.ncconf location when called over COM+ #32

Open gregpakes opened 5 years ago

gregpakes commented 5 years ago

I have a .Net and a Classic ASP application. I have written a COM wrapper for NCache, so I can access it from the Classic ASP. The issue is that when using COM, I can see that it only looks for the client.ncconf and config.ncconf files in c:\windows\system32\inetsrv\config folder rather than the application root folder.

Do you have any suggestion of getting around this? I am trying to share configuration files between my .Net and Classic ASP runtimes, so ideally I want just a single configuration file, but can't see how to specify file location.

gregpakes commented 5 years ago

I have tried putting the files in the bin folder too. That also doesn't work.

Ollie-NCache commented 5 years ago

NCache always looks in the application bin folder first for the "Client.ncconf" file and if it does not find it there then it will go search for it in the NCache installation directory at NCache/Config path. The issue you are referring to is specific to web apps deployed in IIS server that always checks for config files from the "insetsrv" folder by default.

An alternative solution is to use the CacheInitParams in your application when initializing the cache. This will take away any dependencies on client.ncconf file and you can control client side configurations programmatically. I am sharing more details on this below.

CacheInitParams class allows a developer to configure the cache properties directly by code and NCache will then use the properties specified in code rather than checking the config file. A sample code is as follows:

CacheInitParams params = new CacheInitParams();

params.BindIP = "20.200.21.10"   
params.CommandRetries = 5;

You can specify all client side properties that can be found with the documentation of the CacheInitParams class, a link of which is given at the end of this message.

Finally, when you have set all the specific properties that you want to control (all the properties left out will use default values), then simply initialize the cache as:

Cache _cache = NCache.InitializeCache(<cachename>, params)

Helpful Links:

Documentation detailing the CacheInitParams class: http://www.alachisoft.com/resources/docs/ncache/dotnet-api-ref/Alachisoft.NCache.Web.Caching.CacheInitParams.html

Alachisoft article on the CacheInitParams class, its purpose and sample usage: http://www.alachisoft.com/resources/tips/cache-init-params.html

I hope this solves your issue. Please do let me know if you have any other questions.

gregpakes commented 5 years ago

Thanks for the reply.

As per my original post, I have already tried putting the files in the bin folder and this does not work. I get the same error.

I specifically do not want to use CacheInitParams, this is because I am sharing the same config across multiple runtimes (.net and classic ASP), so therefore want to use the file.

Are you saying that it should work when in the bin folder? As I am unable to get this to work. I am using procmon and can see that it never checks the bin for the file.

Ollie-NCache commented 5 years ago

Hello Greg,

As mentioned in my earlier response, NCache looks for client.ncconf file inside the "insetsrv" folder for web applications and this is the default behavior for web applications. However, for other applications. it also checks these files in the application bin folder first. Since you are using a web application, it is going to "insetsrv" folder and for that I had recommended to use CacheInitParams.

Based on your response of using a common repository for NCache configurations files, I discussed this further with engineering and they have recommended a solution that should help you with this.

Here are steps that you can follow to read client.ncconf from a custom path when using Alachisoft Nuget package.

  1. Go to the Windows Registry editor by typing "regedit" in the Windows run command.

  2. Expand _HKEY_LOCALMACHINE in the left pane of the editor and then right-click on SOFTWARE and add new key titled "Alachisoft".

  3. Right-click on "Alachisoft" that you have just created and add new key titled "NCache".

  4. Right-click on "NCache", click on the "New" tab in the drop down list and select "String Value".

  5. Right-click on the new item you see in the right-hand pane and rename it "InstallDir".

  6. Now right-click on "InstallDir" item and select "Modify".

  7. In the resulting pop-up dialog box, write the custom path on your client machine where you will want your application to read client.ncconf file from. For our purposes, lets say the custom path is "D:\NCache"

  8. Assuming your custom path is "D:\NCache", go to D:\, create a new folder NCache and within the NCache folder, create a new folder titled "config". Add your client.ncconf file in this folder

  9. Registry looks like this: _Computer\HKEY_LOCALMACHINE\SOFTWARE\Alachisoft\NCache. registrypic

  10. Your path to the client.ncconf file will look like this in the Windows Explorer address bar: D:\NCache\config. windowsexplorer

Now, if you restart your server, the web app should be able to read from client.ncconf as expected. I hope this resolves your issue.

NOTE: Please note that you can receive your client logs using the same approach. Simply enable client logs in the client.ncconf file and create a folder "log-files" in the same parent folder where your "config" folder is located.

gregpakes commented 5 years ago

Hi,

Thanks for this, but it still doesn’t really help.

As I said, I don’t want a common location from a server perspective. I have multiple applications on a single server all wanting to use cache and I want to store these settings on a per application basis.

I take it from what you’re saying that it isn’t possible from within a web application?

Ollie-NCache commented 5 years ago

Hello Greg,

As explained in earlier responses, there are currently two options that are possible here.

I personally recommend that you use CacheInitParams approach that is specifically designed for such scenarios where you control NCache client side parameters programmatically. You can read NCache client side parameters from a centralized config file that can be shared across apps.

I hope this has been helpful. If you have any further questions, please do let me know.

gregpakes commented 5 years ago

Hi @Ollie-NCache

Thanks for your replies. I completely understand what you're saying, so you don't need to reiterate it again. I just want to point out where this leaves me.

In order to get this to work, I need to use the CacheInitParams. I need to store the config centrally and load it dynamically into each runtime. As I am unable to point the runtime to the client.ncconf file location, I am going to have to create my own file and create a method to deserialise the config into the CacheInitParams. This really feels like I am just duplicating work that you have already done with your config file.

I really wish I could point the runtime to the file location.

Ollie-NCache commented 5 years ago

Hi Greg,

NCache does pick up the client.ncconf file from the local bin folder if it there which is the case for a Windows desktop application, but the issues you are facing stem from the fact that for a web application hosted on IIS, the config files are being picked up from the inetsrv folder that is native IIS behavior which is outside NCache control. The solutions I have proposed are flexible enough to satisfy your requirements in the case of such IIS operation feature. I hope this helps.

gregpakes commented 5 years ago

"Outside of your control"???? Where your application picks up config files is definitely not outside of your control. In fact, I would say that picking it up from the inetsrv is not very common in the space.

It is much more common to pick up config from the root folder of the application. Eg. Web.config, ApplicationInsights.config.... If you look at any 3rd party lib that needs a config, virtually all of them put their config in the root of the application. I am not aware of a single one that uses the inetsrv folder.

Ollie-NCache commented 5 years ago

Hi Greg,

We will look into the matter further and will let you know of any updates.

gregpakes commented 5 years ago

Hi,

Are there any updates on this?

thanks,

Greg

Brad-NCache commented 5 years ago

Hi Greg,

That part is still on-going. However, we are coming out with NCache 5.0 very soon and we'll see if the new features therein will better accommodate your requirements.

gregpakes commented 5 years ago

Thanks @Brad-NCache

Are you able to confirm whether the new features will address this? Or do I just have to wait and see?

Brad-NCache commented 5 years ago

Hello Greg,

I have talked with the engineering team about the features you require and have found that for 5.0, they are not included but I have conveyed your needs to them and they should be introduced in the future.