private ContentDefinitionRecord GetContentDefinitionRecord()
        {
            if (!_memoryCache.TryGetValue <ContentDefinitionRecord>(CacheKey, out var record))
            {
                var changeToken = ChangeToken;

                var typeDefinitions = _cachedTypeDefinitions;
                var partDefinitions = _cachedPartDefinitions;

                // Using local vars prevents the lambda from holding a ref on this scoped service.
                changeToken.RegisterChangeCallback((state) =>
                {
                    typeDefinitions.Clear();
                    partDefinitions.Clear();
                },
                                                   state: null);

                bool cacheable;

                (cacheable, record) = _contentDefinitionStore.GetContentDefinitionAsync().GetAwaiter().GetResult();

                if (cacheable)
                {
                    _memoryCache.Set(CacheKey, record, changeToken);
                }
            }

            return(record);
        }
Пример #2
0
 public async Task <string> GetIdentifierAsync() => (await _contentDefinitionStore.GetContentDefinitionAsync()).Identifier;