fix clearing the script object cache

do not remove all cache entries matching only the instance address:
Also check the constness flag same as its is used in other places
when working with the cache.