Caching results for a single table in selfservicing

Posts   
 
    
dogacozen
User
Posts: 10
Joined: 27-May-2020
# Posted on: 08-Jun-2020 16:17:37   

Hello,

We would like to put a single table into the cache because in our application we make an incredible amount of calls to a relatively small table. We are using selfservicing (with version 5.0).

I saw that in the following article there is a simple solution but I think this is available only using adapters and not selfservicing. Am I right? If so, is there another way to put a table in cache using selfservicing?

https://www.llblgen.com/documentation/4.0/LLBLGen%20Pro%20RTF/Using%20the%20generated%20code/gencode_resultsetcaching.htm

Thanks in advance.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39761
Joined: 17-Aug-2003
# Posted on: 08-Jun-2020 20:16:04   

It's usable in adapter and selfservicing, through Linq and Queryspec, see: https://www.llblgen.com/Documentation/5.7/LLBLGen%20Pro%20RTF/Using%20the%20generated%20code/gencode_resultsetcaching.htm. Resultset caching works by caching the result of a query in the cache you specify/register. If the queries are always different, it's not going to work. However if you e.g. always fetch all rows, then it's very beneficial.

(available since v4.0)

(Please, next time don't post your question in Architecture if it's about the runtime, but place it in the runtime framework forum, thanks)

Frans Bouma | Lead developer LLBLGen Pro
dogacozen
User
Posts: 10
Joined: 27-May-2020
# Posted on: 09-Jun-2020 16:37:29   

Sorry for the wrong category, next time it will be under runtime framework.

I wasn't able to implement the solution you suggested and I suppose that this is because of my lack of knowledge of the framework. Unfortunately the need is urgent. So what we had until now was like the following:

        ProductCollection listOfProducts = new ProductCollection();

        IPredicateExpression selectFilter = new PredicateExpression();
        selectFilter.AddWithAnd(ProductFields.Deleted == false);
        .......
        listOfProducts.GetMulti(selectFilter, 0L, sort, relations);

(where ProductCollection extends EntityCollectionBase)

I tried to add this piece of code before the GetMulti call. QueryFactory qf = new QueryFactory(); DynamicQuery dq = qf.Create().Select(selectFilter).CacheResultset(100);

But I couldn't call GetMulti with a parameter of type DynamicQuery. I thought that I saw in the documentation that this was possible.

What has to be changed in this code so that we can store the results in the cache?

Thanks in advance.

Walaa avatar
Walaa
Support Team
Posts: 14986
Joined: 21-Aug-2005
# Posted on: 09-Jun-2020 22:49:59   

GetMulti() accepts an EntityQuery<TEntity> as specified here To obtain that you should create the QueryFactory with a Type specified ... Create<TEntity>() as specified here

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39761
Joined: 17-Aug-2003
# Posted on: 10-Jun-2020 09:32:39   

See: https://www.llblgen.com/Documentation/5.7/LLBLGen%20Pro%20RTF/Using%20the%20generated%20code/SelfServicing/gencode_usingcollectionclasses.htm#using-a-query

So it comes down to:

var qf = new QueryFactory();
var q = qf.Product
        . .../* joins here */
        .where(ProductFields.Deleted.Equal(false))
        .OrderBy(sort)
        .CacheResultset(100);

var listOfProducts = new ProductCollection();
listOfProducts.GetMulti(q);

If you're more familiar with linq, you can use that too btw, you don't have to use QuerySpec if you don't want to, you can use any query system at any time.

Frans Bouma | Lead developer LLBLGen Pro
dogacozen
User
Posts: 10
Joined: 27-May-2020
# Posted on: 10-Jun-2020 11:32:40   

Thank you!