Domanda

I am caching a collection of activerecord rows (subsonic). When I look at the cache with ANTS Memory Profiler, I can see that some related tables to the activerecord I would like to cache are cached as well. This makes the cached items very large, because of the additionally (not needed) cached tables.

Any ideas on how to prevent this?

È stato utile?

Soluzione

I believe you will have to modify or remove the lazy-loading of relationships in the Active Record classes.

The lazy-loading behavior is generated by the ActiveRecord.tt template, starting at line 300 in the most current version:

        #region ' Foreign Keys '
<#
            List<string> fkCreated = new List<string>();
            foreach(FKTable fk in tbl.FKTables)
            {

                if(!ExcludeTables.Contains(fk.OtherTable)){
                    string propName=fk.OtherQueryable;
                    if(fkCreated.Contains(propName))
                    {
                        propName=fk.OtherQueryable+fkCreated.Count.ToString();
                    }

                    fkCreated.Add(fk.OtherQueryable);


#>
        public IQueryable<<#=fk.OtherClass #>> <#=propName #>
        {
            get
            {

                  var repo=<#=Namespace #>.<#=fk.OtherClass#>.GetRepo();
                  return from items in repo.GetAll()
                       where items.<#=CleanUp(fk.OtherColumn)#> == _<#=CleanUp(fk.ThisColumn)#>
                       select items;
            }
        }

<#
                }
            }

#>
        #endregion

I would try removing this entire region and seeing if the excessive caching is resolved. Of course, if you rely on the lazy-loading behavior you will have to address that now.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top