Closest you can get any remote / portable way:
char dummy[L2_CACHE_SIZE]; memset(dummy, 0, sizeof dummy);
Depending on your processor, there may be privileged opcodes that can clear the cache, but I don't know anything about them or how you can access them. Probably, if they exist, you might still need kernel-level code to use them.
source share