Noah Quanrud

caching-stats (basketball)

Blog

Caching Stats

1. Dilemma

Everytime I would run a functon in EMACS for my Basketball Website or even just loading a page from the site, it would sometimes take over a minute to load due to the large quantity of data it had to process and output. It was a pain to deal with and was looking for a soluting when my brother suggested caching the stats. Caching is the idea of storing data of something computer commonly referred to as Cache.

2. Defining the Caching Function

cache-function
My Common Lisp function for caching player stats.

Originally for just generating the player-stats (the function player-stats-range) the hash table defined within the function with the usage of let and so when the function's use is completed, the hash table is erased. Now by again using let to define the hash table and placing the function within the parameters of the let. Before the hash table was erased after the function ran its course, but now since the table is defined before the function, when the function finishes,the value is left in the hashtable to be accessible for a later time.

3. Slight Limitation

setup
This function will cache all of my play by play stats.

Whenever the code is compiled (the table and function), the contents of the hashtable is whiped. To counter this I made a little expression using progn. With progn it runs eachfunction from the top going down and outputs the last, in this case outputs "complete" to signal the completion of caching the stats. Because of this, "caching" the stats is not perfect, but for the online server and even locally, it does save a lot of time.