{"id":452,"date":"2015-03-11T23:12:47","date_gmt":"2015-03-12T04:12:47","guid":{"rendered":"http:\/\/www.shiftedthought.com\/?p=452"},"modified":"2022-03-09T00:40:33","modified_gmt":"2022-03-09T05:40:33","slug":"my-frustrations-with-the-distributed-cache","status":"publish","type":"post","link":"https:\/\/www.shiftedthought.com\/?p=452","title":{"rendered":"My frustrations with the Distributed Cache"},"content":{"rendered":"<p>The distributed cache was a great idea introduced with SharePoint 2013. \u00a0It truly allows for a load balanced, highly available SharePoint farm where a user no longer needs to retain server affinity. \u00a0If I logged in on web front end 1 somehow get routed to web front end 2, no issues, lets just pull your login tokens, viewstate, and news feeds\u00a0from this new cache shared across all the servers.<\/p>\n<p>That said, so far maintaining it in a large enterprise environment has been a challenge. I have the opportunity(curse) of working in an environment of hundreds of SharePoint servers on premises. Our 2013 footprint is quickly growing; quickly enough that we can&#8217;t keep on top of say, manually, gracefully shutting down our distributed cache services every time an OS patch window rolls around.<\/p>\n<p>Oh and what about those times that Windows just doesn&#8217;t want to play nice and a server blue screens, or worse just hangs. At this point we&#8217;re left with a server with an empty cache, which every other server in the farm thinks should have all of our logon tokens!<\/p>\n<p>SP: Access Denied!!!<br \/>\nBrowser: but I have a valid FedAuth cookie still!<br \/>\nSP: Yeah well I have no idea what happened to your claims so I&#8217;m not sharing<br \/>\nBrowser: but&#8230;FedAuth<br \/>\nSP:\u00a0I&#8217;m just trying to be nice, but I just don&#8217;t think this site has been shared with you.<\/p>\n<p>So where do we go from here. The ideal situation is that before a cache server is restarted, the service is gracefully stopped, then removed.<\/p>\n<p style=\"padding-left: 30px;\">Stop-SPDistributedCacheServiceInstance -Graceful<br \/>\nRemove-SPDistributedCacheServiceInstance<br \/>\n*thank the MS Gods\u00a0for autocomplete&#8230;<\/p>\n<p>And after reboot, re-added.<\/p>\n<p style=\"padding-left: 30px;\">Add-SPDistributedCacheServiceInstance<\/p>\n<p>But, can we fire that automatically for all reboot situations? Well, no, not easily.<\/p>\n<p>1) Any shutdown tasks will not save you in the case of a blue screen, hardware failure, or a guy in the data center tripping over the power cord. \u00a0 The other servers in the farm will not know to rebuild the cache, it&#8217;ll just keep sending the requests to the bads server.<\/p>\n<p>2) There is no ideal\u00a0way to run the Powershell on start up, as a farm account, and please don&#8217;t tell me your farm account is Local Service or Network Service on a multi-server farm. \u00a0The closes you can come is a start up script assigned to the local policy that calls a secondary script that has hardcoded credentials to impersonate a farm admin account.<\/p>\n<p>What we&#8217;re doing:<\/p>\n<p>1) record the last time each server had its distributed cache gracefully started. \u00a0SPServer.Properties is a good place for that<\/p>\n<p>2) Every 30 minutes or so, check this against the server&#8217;s last boot time (WMI)<\/p>\n<p>3) If the last reboot is more recent than the last graceful dist cache start up, tell the farm to rebuild that server&#8217;s cache.<\/p>\n<p>Sprinkle in some (lots of) error handling and call it a day.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The distributed cache was a great idea introduced with SharePoint 2013. \u00a0It truly allows for a load balanced, highly available SharePoint farm where a user no longer needs to retain server affinity. \u00a0If I logged in on web front end 1 somehow get routed to web front end 2, no issues, lets just pull your &hellip; <a href=\"https:\/\/www.shiftedthought.com\/?p=452\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">My frustrations with the Distributed Cache<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[20,3],"tags":[],"class_list":["post-452","post","type-post","status-publish","format-standard","hentry","category-archive","category-sharepoint"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p28JZm-7i","_links":{"self":[{"href":"https:\/\/www.shiftedthought.com\/index.php?rest_route=\/wp\/v2\/posts\/452","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.shiftedthought.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.shiftedthought.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.shiftedthought.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.shiftedthought.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=452"}],"version-history":[{"count":3,"href":"https:\/\/www.shiftedthought.com\/index.php?rest_route=\/wp\/v2\/posts\/452\/revisions"}],"predecessor-version":[{"id":460,"href":"https:\/\/www.shiftedthought.com\/index.php?rest_route=\/wp\/v2\/posts\/452\/revisions\/460"}],"wp:attachment":[{"href":"https:\/\/www.shiftedthought.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=452"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.shiftedthought.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=452"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.shiftedthought.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=452"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}