I think it would be faster to assign count above when it is calculated, to avoid the extra dict lookup. This will be esp. important when you move to storing the cache in a different process (redis/memcached).