return 0 on failure and do caching of results