ISCACHE's forcibly update mechanism

xiaoxiao2021-04-04  232

Background:

In the product, it may not need forced updates, but it is often necessary to test.

Part 1

As you have forced update the cache, the steps are taken as follows:

STEP1)

GENERALCACHEADMINISTRATOR.FLUSHALL ----->

STEP2)

Cache.flushall (Date Date, String Origin)

The source code of Flushall is as follows:

Public void flushall (date date, string Origin) {

// Update Cache's FlushDateTime

Flushdatetime = DATE;

// Notify the listener update event, if you don't have a registered listener, this method is useless

DispatchCacheWideEvent (CacheWideEventType.cache_flushed, Date, Origin);

}

That is to say, just modify the FlushDateTime property of Cache when you forcibly updated.

Not changing data

Part 2

Then you refresh the page to see your forced refresh.

STEP1)

Cache.Getfromcache (String Key, Int Refreshperiod, String cronexpiry) ---->

STEP2)

Cache.isstale (cacheentry, refreshperiod, cronexpiry) ----->

Take a look at the ISSTALE source code:

Protected Boolean Isstale (Cacheentry Cachentry, Int Refreshperiod, String cronexpiry) {

Boolean Result = cachentry.needsRefresh (refreshperiod) || isflushed (cacheentry);

// croneXpiry defines an absolute time, usually you won't use, so the following code is useless

IF (cronexpiry! = null) && (cronexpiry.length ()> 0)) {

Try {

FastcronParser Parser = New FastcronParser (cronexpiry);

Result = result || Parser.haASMoreRenceMatch (cacheentry.getLastUpdate ());

} catch (parseexception e) {

Log.warn (e);

}

}

Return Result;

}

STEP3)

Cache.isflushed (Cacheentry Cachentry)

Take a look at the isflushed source code:

Public Boolean isflushed (Cacheentry Cachentry) {

IF (FlushDateTime! = null) {

Long lastupdate = cacheentry.getlastupdate ();

Return

Flushdatetime.getTime ()> = lastupdate;

} else {

Return False;

}

}

From the above source code, because of cache

FlushDateTime is updated, so it will definitely be greater than the last update time equal to Cachentry, so Cache will think that the cached data is Stale, so it is re-extracted from the database.

All in all: Forcibly update is just a tag, does not really get new data, next time you read data from cache, the cache will be updated from the data based on the mark, even if it is not updated.

转载请注明原文地址:https://www.9cbs.com/read-131932.html

New Post(0)