If all went well, and a contact was sent, create a cache entity for later correlation on exclusive/duplicate/
limit rules.
513171
private function createCache()
    {
        if (!$this->test && $this->valid) {
            try {
                $this->getCacheModel()->create();
            } catch (Exception $e) {
                // Do not log this as an error, because the contact was sent successfully.
                $this->setLogs(
                    'Caching issue which may impact duplicates/exclusivity/limits: '.$e->getMessage(),
                    'warning'
                );
            }
        }
    }
983795
protected ActionResponse handleEntityAlreadyExistsException(ActionRuntime runtime, EntityAlreadyExistsException cause) {
        saveErrors(getErrorsAppAlreadyExistsKey());
        return getErrorMessageAlreadyExistsJsp(runtime);
    }
1231455
public boolean sync(NewRelicCache cache)
    {
        if(cache == null)
            throw new IllegalArgumentException("null cache");

        checkInitialize(cache);
        boolean ret = isInitialized();
        if(!ret)
            throw new IllegalStateException("cache not initialized");

        clear(cache);

        if(ret)
            ret = syncApplications(cache);
        if(ret)
            ret = syncPlugins(cache);
        if(ret)
            ret = syncMonitors(cache);
        if(ret)
            ret = syncServers(cache);
        if(ret)
            ret = syncLabels(cache);
        if(ret)
            ret = syncAlerts(cache);
        if(ret)
            ret = syncDashboards(cache);

        return ret;
    }
999174
private function fileEntitySave()
    {
        if (!$this->file) {
            return;
        }
        if ($this->file->isNew() || $this->file->getChanges()) {
            if ($this->contactClient->getId()) {
                $this->formModel->saveEntity($this->file, true);
            }
        }
    }
276677
def add_result(self, key, result):
        
        if len(self.cache) > self.max_size:
            return
        if key is not None:
            self.cache[key] = result
1110214
@Override
	public void cacheResult(CPRule cpRule) {
		entityCache.putResult(CPRuleModelImpl.ENTITY_CACHE_ENABLED,
			CPRuleImpl.class, cpRule.getPrimaryKey(), cpRule);

		cpRule.resetOriginalValues();
	}
474593
protected DaoResult createOrUpdate(Connection conn, T bo) {
        if (bo == null) {
            return null;
        }
        DaoResult result = create(conn, bo);
        DaoOperationStatus status = result.getStatus();
        if (status == DaoOperationStatus.DUPLICATED_VALUE
                || status == DaoOperationStatus.DUPLICATED_UNIQUE) {
            result = update(conn, bo);
        }
        return result;
    }
1232298
def save(self):
        
        if self.object_id:
            # Update Contact
            if not self._track_changes:
                return True  # there's nothing to update
            url = self.build_url(
                self._endpoints.get('root_contact').format(id=self.object_id))
            method = self.con.patch
            data = self.to_api_data(restrict_keys=self._track_changes)
        else:
            # Save new Contact
            if self.__folder_id:
                url = self.build_url(
                    self._endpoints.get('child_contact').format(
                        folder_id=self.__folder_id))
            else:
                url = self.build_url(self._endpoints.get('contact'))
            method = self.con.post
            data = self.to_api_data(restrict_keys=self._track_changes)
        response = method(url, data=data)

        if not response:
            return False

        if not self.object_id:
            # New Contact
            contact = response.json()

            self.object_id = contact.get(self._cc('id'), None)

            self.__created = contact.get(self._cc('createdDateTime'), None)
            self.__modified = contact.get(self._cc('lastModifiedDateTime'),
                                          None)

            local_tz = self.protocol.timezone
            self.__created = parse(self.created).astimezone(
                local_tz) if self.__created else None
            self.__modified = parse(self.modified).astimezone(
                local_tz) if self.__modified else None
        else:
            self.__modified = self.protocol.timezone.localize(dt.datetime.now())

        return True
115448
def ensure_exists(self):
        """"""
        if not cache.exists(self.config):
            logger.debug("Wily cache not found, creating.")
            cache.create(self.config)
            logger.debug("Created wily cache")
        else:
            logger.debug(f"Cache {self.config.cache_path} exists")
387315
def mark_clean(self, entity):
        
        state = EntityState.get_state(entity)
        state.status = ENTITY_STATUS.CLEAN
        state.is_persisted = True
848681
function afterEntityStored( returnResult, serverResponse ) {
		var self = this;

		// Writing an entity to the backend will usually invoke an update event to be
		// broadcast over websockets, where we would also retrieve the updated record.
		// We still put the updated record we receive here into the cache to ensure early consistency, if that is requested.
		if( !returnResult && !self.forceEarlyCacheUpdate ) {
			return;
		}

		if( serverResponse.data[ configuration.entityName ] ) {
			var rawEntity = serverResponse.data[ configuration.entityName ];
			// If early cache updates are forced, put the return entity into the cache.
			if( self.forceEarlyCacheUpdate ) {
				var newEntity = self.deserializer( rawEntity );
				self.__updateCacheWithEntity( newEntity );

				if( returnResult ) {
					return newEntity;
				}
			}
			if( returnResult ) {
				return rawEntity;
			}
		}
	}
195390
public function createContact() {
        $contact = new Contact($this->getContext());
        $this->addChild($contact);
        $qry = new CreateEntityQuery($contact);
        $this->getContext()->addQuery($qry, $contact);
        return $contact;
    }
1134376
function(exists, done) {
      if (exists) {
        done(new AbstractCache.Error('The cache is currently locked.'))
      } else {
        client.get("lock-process:" + name, done)
      }
    }
1321766
@Override
	public void cacheResult(List<CPFriendlyURLEntry> cpFriendlyURLEntries) {
		for (CPFriendlyURLEntry cpFriendlyURLEntry : cpFriendlyURLEntries) {
			if (entityCache.getResult(
						CPFriendlyURLEntryModelImpl.ENTITY_CACHE_ENABLED,
						CPFriendlyURLEntryImpl.class,
						cpFriendlyURLEntry.getPrimaryKey()) == null) {
				cacheResult(cpFriendlyURLEntry);
			}
			else {
				cpFriendlyURLEntry.resetOriginalValues();
			}
		}
	}
600672
def put_cache_results(self, key, func_akw, set_cache_cb):
        """"""
        args, kwargs = func_akw

        # get function results
        func_results = self.func(*args, **kwargs)

        # optionally add results to cache
        if set_cache_cb(func_results):
            self[key] = func_results
        return func_results
1183700
def submit(self, call, *args, **kwargs):
        
        future = StoredFuture(call, *args, **kwargs)
        self._queue.put(future)
        self._ensure_worker()
        return future
1060470
def _add_complete_key_entity_pb(self):
        
        # We use ``upsert`` for entities with completed keys, rather than
        # ``insert`` or ``update``, in order not to create race conditions
        # based on prior existence / removal of the entity.
        new_mutation = _datastore_pb2.Mutation()
        self._mutations.append(new_mutation)
        return new_mutation.upsert