This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
From the Caching page, it mentions that, "If an explicit ID is not provided (for example, a query that would return all entities from a table) then as LightSpeed receives the result and looks to hydrate an entity it will first check if it already has an entity in the first level cache and, if found, return that entity." And, "The second level cache, if enabled, will also be checked in all of the same situations however it is more likely to contain objects as they will live across the unit of work boundaries." Which sounds to me like the L2 cache isn't immediately referenced UNLESS FindByID is used. If FindByID is NOT used, the database will still be queried first to get the list of entities to "potentially" hydrate. If those entities are already in L2 cache, this step is skipped. So, correct me if I'm wrong, but if I query a base entity, that has multiple related entities, which themselves may be related to more entities, those 2nd (and higher) degree-of-separation-entities ARE first attempted to be pulled from cache? i.e.
will call the database to get the "Person" with "LastName" equaling "Smith." However, in hydrating this entity or any further related entities, i.e. a addresses, phone numbers, etc etc... the Level 2 cache will be checked for the "Person" entity (and related hydrated entities), which has the same ID as the ID of the Person returned (who has the LastName == "Smith"). If that exact Person isn't in Level 2 cache, perhaps multiple people share the same Address, and during hydration of the Person, some of the Address entities may already be in Cache, where they will be retrieved from first. Does this sound right? In other words... if the Entity Type I need is known, and the Identity Key is known, i.e. "Person" with ID: 123, L2 cache will be checked first. (ICache instance per Entity Type, keyed on string "key")? |
|
|
Yes thats correct. For both the L1 and L2 cache we check this based on Id, so in your scenario above there will definitely be a database call to find the matching entity that satisfies that query. If on loading the results we see that we already have that entity in the current UnitOfWork the instance in the L1 cache will be used any the database result will be effectively discarded, otherwise the entity will be materialised from the database result. If we are then lazy loading any to-one associations we will check both the L1 and L2 caches first since we are looking up by Id and if an entity instance exists in either that will be used otherwise we will trigger a database call to fetch the data.
|
|