Skip to content

opendkim.flush_cache()

Christopher Mooney edited this page Feb 12, 2018 · 4 revisions

DESCRIPTION

Flush cached entries when caching is enabled in the library. opendkim.flush_cache() can be called at any time.

For more information:
http://www.opendkim.org/libopendkim/dkim_flush_cache.html

ARGUMENTS

Type: undefined

RETURN VALUES

  • undefined if caching is not active for this library instance.
  • Number of records flushed if caching is active.

NOTES

  • Caching is selected by setting the DKIM_LIBFLAGS_CACHE flag using the opendkim.options() method.
  • Caching requires a special compile-time option to libopendkim since it also adds a library dependency to applications.

EXAMPLE (async/await)

const OpenDKIM = require('node-opendkim');                                                               
                                                                                                         
async function foo() {                                                                                             
  try {
    var opendkim = new OpenDKIM();
    var records = await opendkim.flush_cache();

    if (records) {
      console.log('flushed ' + records + ' records');
    } else {
      console.log('cache is off');
    }
  } catch (err) {                                                                                        
    console.log(err);                                                                                    
  }                                                                                                      
}                                                                                                        

EXAMPLE (sync)

const OpenDKIM = require('node-opendkim');

function foo_sync() {
  try {
    var opendkim = new OpenDKIM();
    var records = opendkim.flush_cache_sync();

    if (records) {
      console.log('flushed ' + records + ' records');
    } else {
      console.log('cache is off');
    }
  } catch (err) {
    console.log(err);
  }
}

EXAMPLE (errback)

const OpenDKIM = require('node-opendkim');

function flush_cache(callback) {
  var opendkim = new OpenDKIM();
  opendkim.flush_cache(function (err, result) {
    callback(err, result);
  });
}

flush_cache(function (err, records) {
  if (err) {
    // handle error
    console.log(err);
    return;
  }

  if (records) {
    console.log('flushed ' + records + ' records');
  } else {
    console.log('cache is off');
  }
});