On Feb 2, 2:32 pm, Fabio Maulo <
fabioma...@gmail.com> wrote:
> I don't think it is viable for gets
>
>
Yeah, we would need an ICache.MultiGet method as well.
Here is my Prefetch implementation for the standard query cache:
public override void Prefetch(IList cacheable,
IEnumerable<ICacheAssembler> returnTypes)
{
if (cacheable == null || cacheable.Count == 0) return;
var prefetchDict = new Dictionary<ICache, ISet<CacheKey>
>();
//note: first index in cacheable is a timestamp
for (var i = 1; i < cacheable.Count; i++)
{
var cacheOid = cacheable[i];
foreach (var type in returnTypes)
{
if (cacheOid ==
LazyPropertyInitializer.UnfetchedProperty ||
cacheOid == BackrefPropertyAccessor.Unknown)
continue;
var entity = type as EntityType;
if (entity == null) continue;
var entityId =
entity.GetIdentifierType(this).Assemble(cacheOid, this, null);
var entityName =
entity.GetAssociatedEntityName(Factory);
var persister =
Factory.GetEntityPersister(entityName);
var entityType = persister.IdentifierType;
var prefetchKey = new CacheKey(entityId,
entityType, entityName, EntityMode, Factory);
var cache = persister.Cache.Cache;
ISet<CacheKey> cacheKeys = null;
if ( !prefetchDict.ContainsKey(cache))
{
cacheKeys = new HashedSet<CacheKey>();
prefetchDict[cache] = cacheKeys;
}
else
{
cacheKeys = prefetchDict[cache];
}
cacheKeys.Add(prefetchKey);
}
}
//prefetch sent to all persister caches
foreach (var cache in prefetchDict.Keys)
{
var keys = prefetchDict[cache];
if (keys.Count > 1)
{
IDictionary results =
cache.MultiGet(prefetchDict[cache]);
//store in local cache
foreach (var key in results.Keys)
{
_prefetchCache.Put(new
CachePutParameters(null, key, results[key]));