To avoid build_schema every time, we cache
        some values: they only change when a SearchIndex
        changes, which typically restarts the Python.
518291
def _update_cache(self):
        
        fields = connections[self.connection_alias].get_unified_index().all_searchfields()
        if self._fields != fields:
            self._fields = fields
            self._content_field_name, self._schema = self.build_schema(self._fields)
20016
def refresh(self):
        
        self.client.indices.refresh(index=self.model.search_objects.mapping.index)
1189532
def clear_cache_fields(self):
        ''''''
        for field in self._meta.scalarfields:
            if field.as_cache:
                setattr(self, field.name, None)
176346
def _set_cached_value(self, xblock, value):
        """"""
        # pylint: disable=protected-access
        if not hasattr(xblock, '_field_data_cache'):
            xblock._field_data_cache = {}
        xblock._field_data_cache[self.name] = value
670732
public void valueChanged(ListSelectionEvent lse) {
        if (!lse.getValueIsAdjusting()) {
            removeListSelectionListener(this);

            // remember everything selected as a result of this action
            HashSet<Integer> newSelections = new HashSet<>();
            int size = getModel().getSize();
            for (int i = 0; i < size; i++) {
                if (getSelectionModel().isSelectedIndex(i)) {
                    newSelections.add(i);
                }
            }

            // turn on everything that was previously selected
            Iterator<Integer> it = selectionCache.iterator();
            while (it.hasNext()) {
                int index = it.next();
                getSelectionModel().addSelectionInterval(index, index);
            }

            // add or remove the delta
            it = newSelections.iterator();
            while (it.hasNext()) {
                Integer nextInt = it.next();
                int index = nextInt;
                if (selectionCache.contains(nextInt)) {
                    getSelectionModel().removeSelectionInterval(index, index);
                } else {
                    getSelectionModel().addSelectionInterval(index, index);
                }
            }

            // save selections for next time
            selectionCache.clear();
            for (int i = 0; i < size; i++) {
                if (getSelectionModel().isSelectedIndex(i)) {
                    selectionCache.add(i);
                }
            }

            addListSelectionListener(this);

        }
    }
965453
def flush_cache(self):
        '''
        
        '''
        logger.debug('Flushing cache {}'.format(self.db_path))
        with self.db:
            for rec in self._tups:
                self.db.execute("replace into history(agent_id, t_step, key, value) values (?, ?, ?, ?)", (rec.agent_id, rec.t_step, rec.key, rec.value))
        self._tups = list()
794132
def _ensure_index_cache(self, db_uri, db_name, collection_name):
        """"""
        if not self._check_indexes or db_uri is None:
            return {'indexes': None}
        if db_name not in self.get_cache():
            self._internal_map[db_name] = {}
        if collection_name not in self._internal_map[db_name]:
            indexes = []
            try:
                if self._index_cache_connection is None:
                    self._index_cache_connection = pymongo.MongoClient(db_uri,
                                                                       document_class=OrderedDict,
                                                                       read_preference=pymongo.ReadPreference.PRIMARY_PREFERRED)

                db = self._index_cache_connection[db_name]
                indexes = db[collection_name].index_information()
            except:
                warning = 'Warning: unable to connect to ' + db_uri + "\n"
            else:
                internal_map_entry = {'indexes': indexes}
                self.get_cache()[db_name][collection_name] = internal_map_entry
        return self.get_cache()[db_name][collection_name]
211611
def refresh_schema(self, exclude_system_tables=True, use_cache=False):
        

        col_meta, table_meta = self._get_db_metadata(exclude_system_tables, use_cache)
        tables = self._gen_tables_from_col_tuples(col_meta)

        # Three modes for refreshing schema
        # 1. load directly from cache
        # 2. use a single query for getting all key relationships
        # 3. use the naive approach
        if use_cache:
            # generate our Tables, and load them into a TableSet
            self._tables = TableSet([Table(self.con, self._query_templates, table_meta[t]['schema'], t, tables[t],
                                           keys_per_column=self.keys_per_column,
                                           foreign_keys=table_meta[t]['foreign_keys']['columns'],
                                           ref_keys=table_meta[t]['ref_keys']['columns'])
                                     for t in sorted(tables.keys())])

        # optimize the foreign/ref key query by doing it one time, database-wide, if query is available
        elif not use_cache and isinstance(self._query_templates.get('system', {}).get('foreign_keys_for_db', None), str):

            self.cur.execute(self._query_templates['system']['foreign_keys_for_db'])
            table_db_foreign_keys = defaultdict(list)
            for rel in self.cur:
                # second value in relationship tuple is the table name
                table_db_foreign_keys[rel[1]].append(rel)

            self.cur.execute(self._query_templates['system']['ref_keys_for_db'])
            table_db_ref_keys = defaultdict(list)
            for rel in self.cur:
                # second value in relationship tuple is the table name
                table_db_ref_keys[rel[1]].append(rel)

            # generate our Tables, and load them into a TableSet
            self._tables = TableSet([Table(self.con, self._query_templates, tables[t][0].schema, t, tables[t],
                                           keys_per_column=self.keys_per_column,
                                           foreign_keys=table_db_foreign_keys[t], ref_keys=table_db_ref_keys[t])
                                     for t in sorted(tables.keys())])
        elif not use_cache:
            self._tables = TableSet([Table(self.con, self._query_templates, tables[t][0].schema, t, tables[t],
                                           keys_per_column=self.keys_per_column) for t in sorted(tables.keys())])

        sys.stderr.write("done!\n")
721081
def ensure_index(self, index, mappings=None, settings=None, clear=False):
        
        mappings = mappings or []
        if isinstance(mappings, dict):
            mappings = [mappings]
        exists = self.indices.exists_index(index)
        if exists and not mappings and not clear:
            return
        if exists and clear:
            self.indices.delete_index(index)
            exists = False

        if exists:
            if not mappings:
                self.indices.delete_index(index)
                self.indices.refresh()
                self.indices.create_index(index, settings)
                return

            if clear:
                for maps in mappings:
                    for key in list(maps.keys()):
                        self.indices.delete_mapping(index, doc_type=key)
                self.indices.refresh()
            if isinstance(mappings, SettingsBuilder):
                for name, data in list(mappings.mappings.items()):
                    self.indices.put_mapping(doc_type=name, mapping=data, indices=index)

            else:
                from pyes.mappings import DocumentObjectField, ObjectField

                for maps in mappings:
                    if isinstance(maps, tuple):
                        name, mapping = maps
                        self.indices.put_mapping(doc_type=name, mapping=mapping, indices=index)
                    elif isinstance(maps, dict):
                        for name, data in list(maps.items()):
                            self.indices.put_mapping(doc_type=name, mapping=maps, indices=index)
                    elif isinstance(maps, (DocumentObjectField, ObjectField)):
                        self.put_mapping(doc_type=maps.name, mapping=maps.as_dict(), indices=index)

                return

        if settings:
            if isinstance(settings, dict):
                settings = SettingsBuilder(settings, mappings)
        else:
            if isinstance(mappings, SettingsBuilder):
                settings = mappings
            else:
                settings = SettingsBuilder(mappings=mappings)
        if not exists:
            self.indices.create_index(index, settings)
            self.indices.refresh(index, timesleep=1)
258409
function saveIndexInfo() {

    // reset the cache
    var tmpCache = cache.idxInfo;
    cache.idxInfo = {};

    var promises = [];

    // add promise for each things being saved/updated
    _.each(tmpCache, function (idxInfo, key) {
        var where = { str: key };
        var select = '_id count';

        var promise = IdxInfoModel.findOne(where, select).exec()
            .then(function (savedItem) {
                if (savedItem) {
                    return IdxInfoModel.findOneAndUpdate(where, { $inc: { count: idxInfo.count }});
                }
                else {
                    var model = new IdxInfoModel(idxInfo);
                    var deferred = Q.defer();
                    model.save(function (modelErr) {
                        modelErr ? deferred.reject(modelErr) : deferred.resolve(model.toObject());
                    });
                    return deferred.promise;
                }
            });

        promises.push(promise);
    });

    return Q.all(promises);
}
151323
void setIndexRoots(Session session, String s) {

        if (!isCached) {
            throw Error.error(ErrorCode.X_42501, tableName.name);
        }

        ParserDQL p     = new ParserDQL(session, new Scanner(s));
        int[]     roots = new int[getIndexCount()];

        p.read();

        for (int i = 0; i < getIndexCount(); i++) {
            int v = p.readInteger();

            roots[i] = v;
        }

        setIndexRoots(roots);
    }
531630
function (propertyName) {
    if (this.isObjectBased) {
      if (!(propertyName in this.attrValue)) { return; }
      delete this.attrValue[propertyName];
      this.data[propertyName] = this.schema[propertyName].default;
    } else {
      this.attrValue = this.schema.default;
      this.data = this.schema.default;
    }
    this.updateProperties(this.attrValue);
  }
1192529
function SqliteSchemaSyncer( db, schema ) {
    this.db = db;
    this.schema = {};
    this.toSync = {};
    this.analyzed = {};
    if ( schema ) {
        this.toSync = schema;
        if ( this.toSync ) {
            for ( var k in this.toSync ) {
                if (this.toSync.hasOwnProperty(k) ) {
                    var value = this.toSync[k];
                    delete this.toSync[k];
                    this.toSync[k.toLowerCase()] = value;
                }
            }
        }
    }
}
760927
public void cacheConcept(Concept concept) {
        conceptCache.put(concept.id(), concept);
        if (concept.isSchemaConcept()) {
            SchemaConcept schemaConcept = concept.asSchemaConcept();
            schemaConceptCache.put(schemaConcept.label(), schemaConcept);
            labelCache.put(schemaConcept.label(), schemaConcept.labelId());
        }
    }
976757
def set_indexing(self, index_template):
        
        objs = object_session(self)
        
        if self.index.indimp != index_template.imp_name:
            self._refresh_datatable_schema()
        
        self.index.name = index_template.name
        self.index.indimp = index_template.imp_name
        self.index.case = index_template.case
        self.index.setkwargs(**index_template.kwargs)
        objs.commit()
802073
function clearField(index, properties) {
        // Aliased fields reflect values on other fields and do not need to be cleared.
        if (properties.isAlias === true) {
            return;
        }

        // In case of object & array, they must be initialized immediately.
        if (properties.type === 'object') {
            this[properties.name].clear();

            // Native arrays are never used so that toArray can be globally supported.
            // Additionally, other properties such as unique rely on passing through SchemaObject.
        } else if (properties.type === 'array') {
            this[properties.name].length = 0;

            // Other field types can simply have their value set to undefined.
        } else {
            writeValue.call(this[_privateKey]._this, undefined, properties);
        }
    }
557041
public static boolean updatingIndexNecessesary(CmsObject cms) {

        // Set request to the offline project.
        setCmsOfflineProject(cms);

        // Check whether the spellcheck index directories are empty.
        // If they are, the index has to be built obviously.
        if (isSolrSpellcheckIndexDirectoryEmpty()) {
            return true;
        }

        // Compare the most recent date of a dictionary with the oldest timestamp
        // that determines when an index has been built.
        long dateMostRecentDictionary = getMostRecentDate(cms);
        long dateOldestIndexWrite = getOldestIndexDate(cms);

        return dateMostRecentDictionary > dateOldestIndexWrite;
    }