Page 1 of 1 1
Topic Options
#185282 - 2008-02-12 03:08 PM Periodically flushing KiXtart tokencahce example
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4672
Loc: The Netherlands
Just an example of how to periodically flush the tokencache.
Lots of ways to get what you want but this is our implementation of it.
The example below flushes the cache every 7 days and uses the TimeDiff UDF to calculate the number of days since the last flush.

UDF Library » TimeDiff() - calculate time difference betweeen 2 timestamps

Since I cant (shouldn’t) post in the example scripts forum I put it here. Maybe if it is up to standards someone (Doc?) can move it to the Example scripts forum.

 Code:
;Read the last flush date from the registry.
$LastFlush = ReadValue("HKU\" + @SID + "\Software\KiXtart\FlushTokenCache", "DateLastFlush")
If TimeDiff($LastFlush, 'Today', 'D') > 7 or $LastFlush = ""
  ;Delete tokencache registry key.
  $rc = DelKey ("HKU\" + @SID + "\Software\KiXtart\TokenCache")
  ;Write now date to the registry for future reference.
  $rc = WriteValue("HKU\" + @SID + "\Software\KiXtart\FlushTokenCache", "DateLastFlush", @DATE, "REG_SZ")
EndIf


Edited by Mart (2008-02-12 04:07 PM)
Edit Reason: Adopted Glenn's code and added a bit to also flush the cache when last flushdate is not available (first run.)
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#185283 - 2008-02-12 03:28 PM Re: Periodically flushing KiXtart tokencahce example [Re: Mart]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
Mart:

Good example of automation!

You might want to look at TimeDiff(), since it can simplify this process.
 Code:
$LastFlush = ReadValue("HKU\" + @SID + "\Software\KiXtart\FlushTokenCache", "DateLastFlush")
If TimeDiff($LastFlush, 'Today', 'D') > 7
  ;Delete tokencache registry key.
  $rc = DelKey ("HKU\" + @SID + "\Software\KiXtart\TokenCache")
  ;Write now date to the registry for future reference.
  $rc = WriteValue("HKU\" + @SID + "\Software\KiXtart\FlushTokenCache", "DateLastFlush", @DATE, "REG_SZ")
EndIf

TimeDiff returns cTime format by default - seconds between the date/time stamps, but you can specify Minutes, Hours, Days, or Years. In this case we use 'D' for Days. It also works with the standard @DATE & @TIME macros, eliminating any fancy time/date formatting.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#185284 - 2008-02-12 03:39 PM Re: Periodically flushing KiXtart tokencahce example [Re: Mart]
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
Oi Mart,

is there any particular reason you don't simply do this?

 Code:
$dayssincelastflush = DateCalc(@date, $lastflush)
_________________________



Top
#185285 - 2008-02-12 03:50 PM Re: Periodically flushing KiXtart tokencahce example [Re: Jochen]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4672
Loc: The Netherlands
Glenn, Jochen,

Will take a look and update. Thanks.
Feel really dumb about the @date thingie Just never thought of it and even after your suggestion I was not sure if @date returns the month and day as two digits and not one if below 10. Seems it does.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#185286 - 2008-02-12 04:04 PM Re: Periodically flushing KiXtart tokencahce example [Re: Mart]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4672
Loc: The Netherlands
Thanks guys. Way smaller and simpler code. I always seem to think and code to complicated thereby sometimes missing obvious things. That’s also one of the reasons I never participated in a KiXgolf round. Because I add lots of checks and comments to my code just to be sure that I understand why I did something the way I did it a year from now.

Updated top post and our main logon script.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#185287 - 2008-02-12 04:29 PM Re: Periodically flushing KiXtart tokencahce example [Re: Mart]
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Depending on your need, the other way to do it is to specify the flush date on the command line.

If you have a tightly controlled environment then you know when a change has been made which will invalidate the cache (like a group being renamed) so when this occurs you just update the date on the flush parameter.

BTW, the cache automatically purges every 30 days.

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
2 registered (morganw, mole) and 414 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.057 seconds in which 0.024 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org