http://russell.ballestrini.net/explaining-cache-with-python/
Also, you might want to look into Sieve of Eratosthenes, as you only have to test up to sqrt(n) for primality: https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes
http://russell.ballestrini.net/explaining-cache-with-python/