MCPcopy Create free account
hub / github.com/Tencent/MMKV / disableAutoKeyExpire

Method disableAutoKeyExpire

Core/MMKV_IO.cpp:1889–1957  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1887}
1888
1889bool MMKV::disableAutoKeyExpire() {
1890 if (isReadOnly()) {
1891 MMKVWarning("[%s] file readonly", m_mmapID.c_str());
1892 return false;
1893 }
1894 SCOPED_LOCK(m_lock);
1895 SCOPED_LOCK(m_exclusiveProcessLock);
1896 checkLoadData();
1897 if (!isFileValid() || !m_metaFile->isFileValid()) {
1898 MMKVWarning("[%s] file not valid", m_mmapID.c_str());
1899 return false;
1900 }
1901
1902 m_expiredInSeconds = 0;
1903 m_enableKeyExpire = false;
1904 if (!m_metaInfo->hasFlag(MMKVMetaInfo::EnableKeyExipre)) {
1905 return true;
1906 }
1907
1908 MMKVInfo("erase previous recorded expire date for all keys inside [%s]", m_mmapID.c_str());
1909 m_metaInfo->unsetFlag(MMKVMetaInfo::EnableKeyExipre);
1910 m_metaInfo->m_version = MMKVVersionFlag;
1911
1912 if (m_file->getFileSize() == m_expectedCapacity && m_actualSize == 0) {
1913 MMKVInfo("file is new, don't need a full write-back [%s], just update meta file", m_mmapID.c_str());
1914 writeActualSize(0, 0, nullptr, IncreaseSequence);
1915 m_metaFile->msync(MMKV_SYNC);
1916 return true;
1917 }
1918
1919 MMKVVector vec;
1920 auto packKeyValue = [&](auto &key, const MMBuffer &value) {
1921 assert(value.length() >= Fixed32Size);
1922 if (value.length() < Fixed32Size) {
1923#ifdef MMKV_APPLE
1924 MMKVWarning("key [%@] has invalid value size %u", key, value.length());
1925#else
1926 MMKVWarning("key [%s] has invalid value size %u", key.data(), value.length());
1927#endif
1928 return;
1929 }
1930 MMBuffer data(value.length() - Fixed32Size);
1931 auto ptr = (uint8_t *) data.getPtr();
1932 memcpy(ptr, value.getPtr(), value.length() - Fixed32Size);
1933 vec.emplace_back(key, std::move(data));
1934 };
1935
1936 auto basePtr = (uint8_t *) (m_file->getMemory()) + Fixed32Size;
1937#ifndef MMKV_DISABLE_CRYPT
1938 if (m_crypter) {
1939 for (auto &pair : *m_dicCrypt) {
1940 auto &key = pair.first;
1941 auto &value = pair.second;
1942 auto buffer = value.toMMBuffer(basePtr, m_crypter);
1943 packKeyValue(key, buffer);
1944 }
1945 } else
1946#endif

Callers 8

test_auto_expireFunction · 0.95
disableAutoExpireFunction · 0.45
disableAutoExpireFunction · 0.45
testAutoExpireFunction · 0.45
disableAutoKeyExpireFunction · 0.45
disableAutoExpireFunction · 0.45
disableAutoExpireFunction · 0.45
testAutoExpirationFunction · 0.45

Calls 9

hasFlagMethod · 0.80
unsetFlagMethod · 0.80
getFileSizeMethod · 0.80
getMemoryMethod · 0.80
toMMBufferMethod · 0.80
isReadOnlyFunction · 0.70
isFileValidFunction · 0.50
isFileValidMethod · 0.45
msyncMethod · 0.45

Tested by 1

test_auto_expireFunction · 0.76