System.DateTime

Just a followup to what I blogged earlier today. Using System.DateTime, one can implement a generic kind of caching in a snap. In the class of your choice:


string oldFile = "/path/to/file"
DateTime fileTime;
DateTime timeNow;
DateTime fileTimePlus;

if ( File.Exists( oldFile )) {
fileTime = File.GetLastWriteTime( oldFile );
timeNow = DateTime.Now;
fileTimePlus = fileTime.AddDays( 1 );

if ( timeNow > fileTimePlus ) {
...do stuff...

So at the do stuff part then you can make a descision about downloading another file, generating another file…on and on.

About Nathan Powell

I am a middle aged technologist freak-ball.
This entry was posted in computers. Bookmark the permalink.

Comments are closed.