//Requests #region Create protected virtual async Task ProcessCreate(PersistenceRequestHolder <K, E> holder) { K key = mTransform.KeyMaker(holder.Rq.Entity); var result = await InternalCreate(key, holder); if (mCacheManager.IsActive && !mCacheManager.IsReadOnly && result.IsSuccess) { mCacheManager.Write(mTransform, result.Entity); } ProcessOutputEntity(key, holder.Rq, holder.Rs, result); }
/// <summary> /// This method writes the entity to the redis cache. /// </summary> /// <param name="transform">The transform holder.</param> /// <param name="entity">The entity to write.</param> /// <param name="expiry"></param> /// <returns>Returns true if the write was successful.</returns> public override async Task <bool> Write(EntityTransformHolder <K, E> transform, E entity, TimeSpan?expiry = null) { if (transform == null) { throw new ArgumentNullException(nameof(transform), "The EntityTransformHolder cannot be null."); } try { K key = transform.KeyMaker(entity); string version = transform.Version.EntityVersionAsString(entity); IDatabase rDb = mLazyConnection.Value.GetDatabase(); IBatch batch = rDb.CreateBatch(); RedisKey hashkey = RedisKeyGet(transform, key); var tasks = new List <Task> { //Entity batch.HashSetAsync(hashkey, cnKeyEntity, transform.CacheEntitySerializer.Serializer(entity), when: When.Always), //Version batch.HashSetAsync(hashkey, cnKeyVersion, version, when: When.Always), // Expiry batch.KeyExpireAsync(hashkey, expiry ?? mEntityTtl) }; //Get any associated references for the entity. var references = transform.ReferenceMaker(entity); references?.ForEach(r => tasks.AddRange(WriteReference(batch, transform, r, key, version))); batch.Execute(); await Task.WhenAll(tasks); return(true); } catch (Exception) { // Don't raise an exception here } return(false); }