'Initialize this cache with data from the backend.'

@api
def init(self):

    with self.write_lock:
        self.backend.read_tables()
        bools_are_tristate = self.backend.prefs[u'bools_are_tristate']
        for (field, table) in self.backend.tables.iteritems():
            self.fields[field] = create_field(field, table, bools_are_tristate, self.backend.get_template_functions)
            if (table.metadata[u'datatype'] == u'composite'):
                self.composites[field] = self.fields[field]
        self.fields[u'ondevice'] = create_field(u'ondevice', VirtualTable(u'ondevice'), bools_are_tristate, self.backend.get_template_functions)
        for (name, field) in self.fields.iteritems():
            if ((name[0] == u'#') and name.endswith(u'_index')):
                field.series_field = self.fields[name[:(- len(u'_index'))]]
                self.fields[name[:(- len(u'_index'))]].index_field = field
            elif (name == u'series_index'):
                field.series_field = self.fields[u'series']
                self.fields[u'series'].index_field = field
            elif (name == u'authors'):
                field.author_sort_field = self.fields[u'author_sort']
            elif (name == u'title'):
                field.title_sort_field = self.fields[u'sort']
    if self.backend.prefs[u'update_all_last_mod_dates_on_start']:
        self.update_last_modified(self.all_book_ids())
        self.backend.prefs.set(u'update_all_last_mod_dates_on_start', False)
