firely-net-sdk icon indicating copy to clipboard operation
firely-net-sdk copied to clipboard

Permit all Caches to be externally provided

Open brianpos opened this issue 5 years ago • 6 comments

My server has several internal caches, and specific handling around these and would like to be able to have access to all caches in the validator, and everywhere else so that preferably we can provide the implementation to use, and at least access to the cache so that we can display data as to what is in it (a diagnostic/status display) and a public function to be able to flush it.

So far I've identified the fhirpath compiled expression cache - totally internal, and no flush capability and I'm using the CachedResolver to, but that doesn't have any diagnostic abilities (thankfully can flush it) To resolve the above 2 issues, i've had to use reflection to crack into them.

brianpos avatar Jul 25 '19 07:07 brianpos

Yes, that seems like a good idea. There is already a universal Cache class but that's not used across the board. I will keep this in mind when I refactor the FP engine in the coming months.

What kind of diagnostic abilities are you looking for? cache hits/misses etc?

ewoutkramer avatar Jul 29 '19 09:07 ewoutkramer

Just count, access to what's in there and expiry (or whatever cache status stuff there is inside) And most importantly a mechanism to force a flush.

brianpos avatar Jul 29 '19 09:07 brianpos

My fork has some code that I'm using that could assist with this https://github.com/brianpos/fhir-net-api/commit/03957a2888e83671680abccd97929e987096517f https://github.com/brianpos/fhir-net-api/commit/a866cf134d17c8da3c6cd194900bdff0ce9708f0 At least to see what I'm reaching into for my cache internal status reporting/logging

brianpos avatar Jul 30 '19 08:07 brianpos

FYI .NET provides an abstract base class for cache implementations: https://docs.microsoft.com/en-us/dotnet/api/system.runtime.caching.objectcache?view=netframework-4.8 https://docs.microsoft.com/en-us/dotnet/api/system.runtime.caching.memorycache?view=netframework-4.8

wmrutten avatar Aug 05 '19 09:08 wmrutten

We will scope this to the cache of the FhirPath Compiler and the CachedResourceResolver.

EnumMapping, ClassMapping and ModelInspector are out of scope, because these will never grow indefinitely or out of proportion.

The downside of adding externally provided caches are that we have to define an interface that specifies what we cache, and it's therefor harder to change or improve these without breaking that interface.

This is the reason why we don't want to allow it, so we want it easier to change settings of the internal chaches

Add:

  • Flush function
  • Max Size setting
  • Expiration time setting

Maybe more

We should first design this, this is not straight forward, and need to thing about reasonable defaults. Also think about moving to .NET MemoryChache or https://learn.microsoft.com/en-us/dotnet/api/microsoft.extensions.caching.distributed.memorydistributedcache?view=net-8.0, we can also decide to keep our own implementation, let's review what the upsides and downsides of moving are.

mmsmits avatar May 02 '24 08:05 mmsmits

Not a priority for me these days. What I added was a way to flush it, and report on the size.

brianpos avatar May 02 '24 09:05 brianpos