mIRC Homepage
Posted By: hixxy $finddir/$findfile - cached list. - 13/02/06 03:27 PM
I think it would be really nice if there was a cached list of results for the last $findfile call.

$findfile($mircdir,*.txt,0)
$findfilecache(1) -> 1.txt
$findfilecache(2) -> 2.txt
$findfilecache(3) -> 3.txt
$findfile($mircdir,*.mrc,0)
$findfilecache(1) -> 1.mrc
$findfilecache(2) -> 2.mrc
$findfilecache(3) -> 3.mrc
Etc..

$finddir would do the same.
Posted By: qwerty Re: $finddir/$findfile - cached list. - 13/02/06 04:03 PM
If something like this was implemented, the cached data should be cleared as soon as the routine (alias or event) that called $findfile was finished, otherwise the cache could end up with invalid data (eg if a file is deleted in the meantime).

With this in mind, I can't see much use for it, as found filenames can already be referenced multiple times: either by $1- inside the alias in $findfile(dir,mask,0,alias $1-) or by $line(@win,N) after a $findfile(dir,mask,0,@win). The only case where this could be useful is if you call $findfile(dir,mask,0) (without a 4th parameter) to get the number of all matching files and later (in the same routine) you want to reference a single file (or certain files) by index, for example just get the 3rd and the 5th filename. This is a rather odd scenario though, I have never needed such a thing nor can I think of why anyone would. Can you give an example of a real-world use of such a feature?

On a sidenote, you probably know this already, but caching is already done by the system at the appropriate level, which is why subsequent calls of the same $findfile() are much faster.
Posted By: hixxy Re: $finddir/$findfile - cached list. - 13/02/06 04:09 PM
Really it'd just be for consistency with most other code (being able to use a while loop to loop through found files without a ridiculous speed decrease.)

Code:
alias listfiles {
  var %count = $findfile($mircdir,*.mrc,0), %i = 1
  while ($findfilecache(%i)) {
    echo -a $v1
    inc %i
  }
  echo -a * %count files found.
}


Most things in mIRC use loops; $hget, $timer, $read, $window, etc. Only a few rare cases use callbacks.
Posted By: Sat Re: $finddir/$findfile - cached list. - 13/02/06 04:19 PM
Quote:
Most things in mIRC use loops; $hget, $timer, $read, $window, etc. Only a few rare cases use callbacks.

But none of those use a cache, even though that would be very desirable for e.g. $comval and $hget/$hfind. Unlike those, $findfile already gives you the opportunity to do the caching yourself, if you want to - if you don't, then mIRC would only eat up lots of memory by caching results you'll never use again.. So if this were to be added, it should at least be optional IMO.
Posted By: qwerty Re: $finddir/$findfile - cached list. - 13/02/06 04:42 PM
For completeness' sake, I wouldn't mind having this too. Now that I think of it, this way you wouldn't have to pass parameters from the calling routine to the $findfile() alias or set up global vars etc either. I just thought you had something in mind that couldn't be done efficiently with the traditional methods (I tend to think economically regarding feature suggestions, seeing as there are too many of them for one programmer wink)

Edit: Sat's got a point too, the extra memory might matter when dealing with thousands of results
Posted By: hixxy Re: $finddir/$findfile - cached list. - 14/02/06 01:24 AM
It could be optional with a property; $findfile().cache - make the cache (doesn't make it by default) / or $findfile().nocache - don't make the cache (makes it by default.)

As for the cache being cleared after the current routine ends (re: qwerty) I think that kinda defeats the point of having it (ie not having to use the same subsequent $findfile calls.) I think it should just be reset with each $findfile call and maybe there could be a command added to clear it.
Posted By: qwerty Re: $finddir/$findfile - cached list. - 14/02/06 01:38 AM
There's already a $findfile() property, .shortfn. This and .cache aren't mutually exclusive so this can't work.
Posted By: hixxy Re: $finddir/$findfile - cached list. - 14/02/06 01:47 AM
Good point. Maybe an optional $true/$false parameter then ($false if not supplied.)
© mIRC Discussion Forums