Ejemplo n.º 1
0
        public async Task <TreeNode <NavigationNode> > GetTree()
        {
            // ultimately we will need to cache sitemap per site

            if (rootNode == null)
            {
                await cache.ConnectAsync();

                byte[] bytes = await cache.GetAsync(cacheKey);

                if (bytes != null)
                {
                    string json = Encoding.UTF8.GetString(bytes);
                    rootNode = BuildTreeFromJson(json);
                }
                else
                {
                    rootNode = await BuildTree();

                    string json = rootNode.ToJsonCompact();

                    await cache.SetAsync(
                        cacheKey,
                        Encoding.UTF8.GetBytes(json),
                        new DistributedCacheEntryOptions().SetSlidingExpiration(
                            TimeSpan.FromSeconds(100))
                        );
                }
            }

            return(rootNode);
        }
        public async Task <TreeNode <NavigationNode> > GetTree()
        {
            // ultimately we will need to cache sitemap per site
            // we will implement a custom ICacheKeyResolver to resolve multi tenant cache keys

            if (rootNode == null)
            {
                log.LogDebug("rootnode was null so checking distributed cache");
                string cacheKey = cacheKeyResolver.ResolveCacheKey(options.CacheKey);

                NavigationTreeXmlConverter converter = new NavigationTreeXmlConverter();

                await cache.ConnectAsync();

                byte[] bytes = await cache.GetAsync(cacheKey);

                if (bytes != null)
                {
                    log.LogDebug("rootnode was found in distributed cache so deserializing");
                    string    xml = Encoding.UTF8.GetString(bytes);
                    XDocument doc = XDocument.Parse(xml);

                    rootNode = converter.FromXml(doc);
                }
                else
                {
                    log.LogDebug("rootnode was not in cache so building");

                    rootNode = await implementation.GetTree();

                    string xml2 = converter.ToXmlString(rootNode);

                    await cache.SetAsync(
                        cacheKey,
                        Encoding.UTF8.GetBytes(xml2),
                        new DistributedCacheEntryOptions().SetSlidingExpiration(
                            TimeSpan.FromSeconds(options.CacheDurationInSeconds))
                        );
                }
            }

            return(rootNode);
        }
Ejemplo n.º 3
0
        public async Task <TreeNode <NavigationNode> > GetTree()
        {
            // ultimately we will need to cache sitemap per site

            if (rootNode == null)
            {
                NavigationTreeXmlConverter converter = new NavigationTreeXmlConverter();

                await cache.ConnectAsync();

                byte[] bytes = await cache.GetAsync(cacheKey);

                if (bytes != null)
                {
                    string    xml = Encoding.UTF8.GetString(bytes);
                    XDocument doc = XDocument.Parse(xml);

                    rootNode = converter.FromXml(doc);
                }
                else
                {
                    rootNode = await BuildTree();

                    string xml2 = converter.ToXmlString(rootNode);

                    await cache.SetAsync(
                        cacheKey,
                        Encoding.UTF8.GetBytes(xml2),
                        new DistributedCacheEntryOptions().SetSlidingExpiration(
                            TimeSpan.FromSeconds(100))
                        );
                }
            }

            return(rootNode);
        }