I have a little system that I have set up, that receives incoming requests from my client sites. The results of these requests are then cached to the file system, to reduce the load on the server the next time the same request is performed.
I use the following method to generate the cache filename:
- I generate an MD5 hash of the requested URL.
- I then create a directory in
, where the
values are the positions of those letters.
- I then truncate this hash, and save the file in the before-mentioned directory.
For example, the hash for http://www.google.co.za
. The cache file for this request would be in
I'm needing to keep track of the number of these cache files. I don't care about which directories they're in, I just need to know a total count of files only in /tmp/cache/.
Currently, I'm using
find /tmp/cache -type f | wc -l
to generate this count of files. However, I've noticed that it's taking longer and longer to find these files (and uses more processing power than I'd like).
At the moment, there are about 370,000 files in the directory, and the file system is an EXT4 file system.
Does anyone have a better and more efficient method than this for finding the count of files? Please? :)