Skip to content

Using Bytes versions

Jon P Smith edited this page Aug 3, 2022 · 4 revisions

There are two FileStore distributed cache versions that have the value of type byte[]. They are:

| Version name | Description | | Bytes | This provides all the methods in the String version, but with a value of byte[] | | IDistributedCache | This registers Bytes version against the IDistributedCache interface, so the extra methods are hidden |

The other difference is the Bytes and IDistributedCache versions contain a Refresh / RefreshAsync to match the IDistributedCache interface, but because the FileStore cache doesn't supports the SlidingExpiration if you call these methods they will throw an NotImplementedException. Also, if the SlidingExpiration isn't null in the DistributedCacheEntryOptions in the Set / SetAsync methods, then will throw an NotImplementedException too.

These are here for people who are already using distributed caches that implement the IDistributedCache.

Standard IDistributedCache methods

Type Method names
Read a cache entry Get(string key) / GetAsync(string key)
Create/Update a cache entry Set(string key, byte[] value,...) / SetAsync(string key, byte[] value,...)
Delete a cache entry Remove(string key) / RemoveAsync(string key, ...)

Extra FileStore cache methods (only in the Bytes interface)

Type Method names
Get ALL cache entries GetAllKeyValues / GetAllKeyValuesAsync(...)
Remove all cache values ClearAll

NOTE: Its worth reading this section of the Tips on making your cache fast document to understand that binary data might be bigger that you think.

How to use these versions

When you register the FileStore cache the interface that you should use depends on which bytes[] version you select.

Version interface
Bytes IDistributedFileStoreCacheBytes
IDistributedCache IDistributedCache

As I expect users that want to use either of these versions will already be aware of the IDistributedCache, and the extra FileStore cache methods have been described in the Using String version documentation.

Clone this wiki locally