// fileCache.c : Implements a file cache for reading and writing // INCLUDE #include #include #include "fileCache.h" // GLOBAL VARIABLES char cacheFile1[] = "C:\\FTPCACH1.TMP"; char cacheFile2[] = "C:\\FTPCACH2.TMP"; FtpFh ftpfh1; FtpFh ftpfh2; int LRU = 1; // FUNCTION DEFINITIONS LPSTR CheckCache(FtpFh ftpfh) { if ( ftpfh == ftpfh1 ) { LRU = 2; printf("Hit FileCache: 1\n"); return cacheFile1; } else if ( ftpfh == ftpfh2 ) { LRU = 1; printf("Hit FileCache: 2\n"); return cacheFile2; } else { printf("Miss FileCache\n"); return NULL; } } LPSTR CacheFile(FtpFh ftpfh) { if ( LRU == 1 ) { LRU = 2; ftpfh1 = ftpfh; printf("Caching file: 1\n"); return cacheFile1; } else if ( LRU == 2 ) { LRU = 1; ftpfh2 = ftpfh; printf("Caching file: 2\n"); return cacheFile2; } else { printf("ERROR.... BAD LRU\n"); return NULL; // should never occur } } void InvalidateFileCache() { ftpfh1 = NULL; ftpfh2 = NULL; LRU = 1; }