public void Set(string key, CacheItem cacheItem) {
            lock (String.Intern(key)) {
                var records = _repository.Table.Where(x => x.CacheKey == key).ToList();
                var record = records.FirstOrDefault();
                    
                if (record == null) {
                    record = new CacheItemRecord();
                    Convert(cacheItem, record);
                    _repository.Create(record);
                    return;
                }

                Convert(cacheItem, record);
            }
        }
 private void Convert(CacheItem cacheItem, CacheItemRecord record) {
     record.CacheKey = cacheItem.CacheKey;
     record.CachedOnUtc = cacheItem.CachedOnUtc;
     record.Duration = cacheItem.Duration;
     record.GraceTime = cacheItem.GraceTime;
     record.ValidUntilUtc = cacheItem.ValidUntilUtc;
     record.StoredUntilUtc = cacheItem.StoredUntilUtc;
     record.ContentType = cacheItem.ContentType;
     record.InvariantCacheKey = cacheItem.InvariantCacheKey;
     record.Output = cacheItem.Output;
     record.QueryString = cacheItem.QueryString;
     record.StatusCode = cacheItem.StatusCode;
     record.Tags = String.Join(";", cacheItem.Tags);
     record.Tenant = cacheItem.Tenant;
     record.Url = cacheItem.Url;
 }
        private CacheItem Convert(CacheItemRecord record) {
            var cacheItem = new CacheItem();

            cacheItem.CacheKey = record.CacheKey;
            cacheItem.CachedOnUtc = record.CachedOnUtc;
            cacheItem.Duration = record.Duration;
            cacheItem.GraceTime = record.GraceTime;
            cacheItem.ContentType = record.ContentType;
            cacheItem.InvariantCacheKey = record.InvariantCacheKey;
            cacheItem.Output = record.Output;
            cacheItem.QueryString = record.QueryString;
            cacheItem.StatusCode = record.StatusCode;
            cacheItem.Tags = record.Tags.Split(';');
            cacheItem.Tenant = record.Tenant;
            cacheItem.Url = record.Url;

            return cacheItem;
        }