public static async Task <IList <IServiceInstance> > GetInstancesWithCacheAsync(
            this IServiceInstanceProvider serviceInstanceProvider,
            string serviceId,
            IDistributedCache distributedCache        = null,
            DistributedCacheEntryOptions cacheOptions = null,
            string serviceInstancesKeyPrefix          = "ServiceInstances:")
        {
            // if distributed cache was provided, just make the call back to the provider
            if (distributedCache != null)
            {
                // check the cache for existing service instances
                var instanceData = await distributedCache.GetAsync(serviceInstancesKeyPrefix + serviceId).ConfigureAwait(false);

                if (instanceData != null && instanceData.Length > 0)
                {
                    return(DeserializeFromCache <List <SerializableIServiceInstance> >(instanceData).ToList <IServiceInstance>());
                }
            }

            // cache not found or instances not found, call out to the provider
            var instances = serviceInstanceProvider.GetInstances(serviceId);

            if (distributedCache != null)
            {
                await distributedCache.SetAsync(serviceInstancesKeyPrefix + serviceId, SerializeForCache(MapToSerializable(instances)), cacheOptions ?? new DistributedCacheEntryOptions()).ConfigureAwait(false);
            }

            return(instances);
        }