static void Main(string[] args) { DownloadCache removed = new DownloadCache(10); int current; timestamp("About to make the cache"); current = removed.setCache(removed.nextFree(), "https://people.freebsd.org/~crees/removed_ports/index.xml"); timestamp("Cache made, now let's try to access it and get the first thirty characters..."); Console.WriteLine(removed.getCache(current).Substring(0, 30)); timestamp("Let's try again..."); Console.WriteLine(removed.getCache(current).Substring(0, 30)); timestamp("Woah, that was quicker!"); }
/* Outputs the current timestamp so the user can compare the speeds */ static void Main(string[] args) { DownloadCache cache = new DownloadCache(2); int first, second, counter1, counter2; counter1 = 0; counter2 = 0; timestamp("About to make the cache"); first = cache.nextFree(); cache.setCache(first, "https://people.freebsd.org/~crees/removed_ports/index.xml"); timestamp("Cache made, now let's try to access it and get the first thirty characters..."); Console.WriteLine(cache.getCache(first).Substring(0, 30)); counter1 += 1; /* Counter will count how many times getCache has been used */ timestamp("Let's try again..."); Console.WriteLine(cache.getCache(first).Substring(0, 30)); counter1 += 1; timestamp("Woah, that was quicker!"); second = cache.nextFree(); cache.setCache(second, "another_slow_url"); Console.WriteLine(cache.getCache(second).Substring(0, 30)); counter2 += 1; Console.WriteLine(cache.getCache(second).Substring(0, 30)); counter2 += 1; Console.WriteLine(cache.getCache(second).Substring(0, 30)); counter2 += 1; Console.WriteLine(cache.getCache(second).Substring(0, 30)); counter2 += 1; if (counter1 < counter2) { ; } { cache.setCache(first, null); } if (counter2 < counter1) { ; } { cache.setCache(second, null); /* Removes the cache item that has the least amount of accesses */ } /* Find the next free one and see which one has been deleted- which one should be deleted? */ }
static void Main(string[] args) { DownloadCache cache = new DownloadCache(2); int first, second; timestamp("About to make the cache"); // Prints the current timestamp to the console alongside a strings first = cache.nextFree(); // Finds the next available space, or returns the least used cache if there is no space available cache.setCache(first, "https://people.freebsd.org/~crees/removed_ports/index.xml"); // Sets the cache to a url timestamp("Cache made, now let's try to access it and get the first thirty characters..."); // Prints the timestamp to the console so that the time taken to cache the webpage can be recorded Console.WriteLine(cache.getCache(first).Substring(0, 30)); // Prints the first 30 characters from the cache to the console timestamp("Let's try again..."); // Prints the timestamp agan Console.WriteLine(cache.getCache(first).Substring(0, 30)); // Again, accesses the cache timestamp("Woah, that was quicker!"); // Then records the timestamp to compare how long it took to load second = cache.nextFree(); // Ditto line 140 cache.setCache(second, "https://google.com"); // Caches another url Console.WriteLine(cache.getCache(second).Substring(0, 30)); Console.WriteLine(cache.getCache(second).Substring(0, 30)); Console.WriteLine(cache.getCache(second).Substring(0, 30)); Console.WriteLine(cache.getCache(second).Substring(0, 30)); /* Find the next free one and see which one has been deleted- which one should be deleted? */ }
static void Main(string[] args) { DownloadCache cache = new DownloadCache(2); int first, second; timestamp("About to make the cache"); first = cache.nextFree(); cache.setCache(first, "https://people.freebsd.org/~crees/removed_ports/index.xml"); timestamp("Cache made, now let's try to access it and get the first thirty characters..."); Console.WriteLine(cache.getCache(first).Substring(0, 30)); timestamp("Let's try again..."); Console.WriteLine(cache.getCache(first).Substring(0, 30)); timestamp("Woah, that was quicker!"); second = cache.nextFree(); cache.setCache(second, "another_slow_url"); Console.WriteLine(cache.getCache(second).Substring(0, 30)); Console.WriteLine(cache.getCache(second).Substring(0, 30)); Console.WriteLine(cache.getCache(second).Substring(0, 30)); Console.WriteLine(cache.getCache(second).Substring(0, 30)); /* Find the next free one and see which one has been deleted- which one should be deleted? */ }