Showing posts with label Cache lookup. Show all posts
Showing posts with label Cache lookup. Show all posts

Monday, November 17, 2025

cache lookup:

 cache lookup: 

  

  

http://gautamax.blogspot.com/2017/01/cache-lookup-property-of-table-in-ax.html 

  

https://learn.microsoft.com/en-us/dynamicsax-2012/developer/single-record-caching 

  

  

>> Caches are used on both the client and the server. It increases the performance, the ax will get data from the cache instead of doing round trips and DB calls. So for each table, it's good to use cache lookup property. Microsoft Dynamics Ax runtime manages the cache by removing old records when new records are added to the cache. 

  

>> The maximum number of records can be maintained in a client cache is 100 records per table for the selected company. 

  

>>  The maximum number of records maintained in a server cache is 2000 records for the selected company. 

  

None: 

No data is cached or retrieved from the cache for this table. This property value should be used for tables that are heavily updated or where it's unacceptable to read outdated data. 

  

EntireTable: 

Creates a set-based cache on the server. The entire table is cached as soon as at least one record is selected from the table. An EntireTable cahce is flushed whenever an insert, update or delete is made to the table. So first select read all records from DB for the selected company and all the further selects will take data from the cache instead of DB calls. 

  

Found 

All successful caching key selects are cached. All caching key selects are returned from the cache if the record exists there. A select forUpdate in a transaction forces reading from the database and replaces the record in the cache. 

This is typically used for static (lookup) tables, such as Unit, where the record usually exists. 

  

NotInTTS 

All successful caching key selects are cached. 

When in a transaction (after ttsBegin), no caches made outside the transaction are used. When inside a transaction, the record is read once from the database and subsequently from the cache. The record is select-locked when reading in a transaction, which ensures that the record cached is not updated while the transaction is active. 

A typical example of the NotInTTS property is on the CustTable in the Microsoft Dynamics AX application. It is acceptable to read outdated data from the cache outside a transaction, but when data is used for validation or creating references, it is ensured that the data is real-time. 

  

FoundAndEmpty  

All selects on caching keys are cached, including selects that are not returning data. 

All caching key selects are returned from caching if the record exists there, or the record is marked as nonexistent in the cache. A select forUpdate in a transaction forces reading from the database and replaces the record in the cache. 

An example of FoundAndEmpty record caching is in the Discount table in the Microsoft Dynamics AX standard application. By default, the Discount table has no records. By using a FoundAndEmpty cache on this table, the keys that are queried for but not found are stored in the cache. Subsequent queries for these same non-existent records can be answered from the cache without a round trip to the database.  

  

  

Extras okay in Where clause 

  

An X++ Select statement can have a Where clause that contains equality tests on all fields of any unique index, plus additional tests of other fields. The additional tests must be added with the && operator, not with ||. Such additional tests no longer prevent the caching mechanisms from improving performance. The following X++ select statement is an example of such a join. 

  

select * from tabCustTable  

where tabCustTable.AccountNum == "4000" &&  

tabCustTable.CustGroup == "Gold"; 

  

join is supported 

  

An X++ Select statement that joins tables can now be included in the caching processes. The Where clause must contain an equality test on a caching index. The following X++ select statement is an example of such a join. 

  

select from tabCustTable join tabCustGroup  

where tabCustTable.AccountNum == "4000" &&  

tabCustTable.CustGroup == tabCustGroup.CustGroup; 

  

The preceding Select Join would cause the following Select to be serviced by the cache: 

  

select from tabCustGroup  

where tabCustGroup.CustGroup == "Gold"; 

  

Cross-company queries 

  

Queries that use the crossCompany keyword of X++ are supported for caching when there is only a single company involved. 

  

>>>>>>>>>>>>> 

what is key based caching ?? 

what is set based ?? 

what is foun?? 

what is found&empty ?? 

  

select example where example.Idx == 50; 

  

info(strFmt("Test step 1 : %1", example.wasCached())); 

  

  

found: 

static  void tableCachingTest(Args _args)</pre> 

{ 

  

CachedTableExample example; 

  

int i; 

  

; 

  

select example where example.Idx == 50; 

  

info(strFmt("Test step 1 : %1", example.wasCached())); 

  

//Second select comes from cache 

  

select example where example.Idx == 50; 

  

info(strFmt("Test step 2 : %1", example.wasCached())); 

  

  

  

//Recid select 

  

select example where example.Recid == 5637145628; 

  

info(strFmt("Test step 3 : %1", example.wasCached())); 

  

  

  

//Forupdate select 

  

select forupdate example where example.Recid == 5637145628; 

  

info(strFmt("Test step 3 : %1", example.wasCached())); 

  

} 

  

ANS: not cached,recordcached,recordcached,recordcached 

  

foun&foundempty: 

static  void tableCachingTest(Args _args) 

  

{ 

  

CachedTableExample example; 

  

int i; 

  

; 

  

select example where example.Idx == 50; 

  

info(strFmt("Test step 1 : %1", example.wasCached())); 

  

//Second select comes from cache 

  

select example where example.Idx == 50; 

  

info(strFmt("Test step 2 : %1", example.wasCached())); 

  

//Empty select 

  

select example where example.Idx == 1050; 

  

info(strFmt("Test step 3 : %1", example.wasCached())); 

  

//Empty select second 

  

select example where example.Idx == 1050; 

  

info(strFmt("Test step 4 : %1", example.wasCached())); 

  

//Another field empty select 

  

select forupdate example where example.value == 'doesnotexists'; 

  

info(strFmt("Test step 5 : %1", example.wasCached())); 

  

//Another field empty select second time 

  

select forupdate example where example.value == 'doesnotexists'; 

  

info(strFmt("Test step 6 : %1", example.wasCached())); 

  

} 

  

ANS: 

notcached,Recordcached,notcached,Recordcached,notcached,Recordcached.