'Save the UIDVALIDITY value of the folder to the cache
This function is not threadsafe, so don\'t attempt to call it
from concurrent threads.'

def save_uidvalidity(self):

    newval = self.get_uidvalidity()
    uidfilename = self._getuidfilename()
    with open((uidfilename + '.tmp'), 'wt') as uidfile:
        uidfile.write(('%d\n' % newval))
    os.rename((uidfilename + '.tmp'), uidfilename)
    self._base_saved_uidvalidity = newval
