[{"data":1,"prerenderedAt":3807},["ShallowReactive",2],{"blog-go-in-memory-cache":3,"blog-all-for-related":3314},{"id":4,"title":5,"author":6,"body":7,"cardAlt":5,"categories":3300,"description":3302,"draft":3303,"extension":3304,"headerImage":3305,"keywords":3306,"meta":3307,"name":3308,"navigation":159,"path":3309,"seo":3310,"series":6,"stem":3311,"updated":6,"year":3312,"__hash__":3313},"blog\u002Fblog\u002Fgo-in-memory-cache.md","Building In-Memory Cache in Go",null,{"type":8,"value":9,"toc":3291},"minimark",[10,19,24,27,34,41,55,3287],[11,12,13,14,18],"p",{},"In the ever-evolving landscape of software development, performance is a crucial factor. Whether you're building a web application, a microservice, or any other software system, optimizing for latency on your APIs (response times) can ",[15,16,17],"strong",{},"enhance user experience"," and reduce operational costs (CPU\u002FMemory). One effective technique for achieving performance gains is through the use of in-memory caching. In this blog, we'll deep dive into implementing an in-memory cache in Go (both using generics and non-generics way)",[20,21,23],"h2",{"id":22},"introduction","Introduction",[11,25,26],{},"Before going into implementation, let's discuss about in-memory caching and it's advantages.",[11,28,29,30,33],{},"In-memory caching involves storing frequently accessed data in memory for ",[15,31,32],{},"quick retrieval",", rather than fetching it from a slower data store, such as a database, every time it's needed. This can significantly reduce latency and improve overall system performance.",[11,35,36,37,40],{},"Go using it's ",[15,38,39],{},"lightweight goroutines"," and channels make it straightforward to build highly concurrent systems, which is ideal for handling cache operations efficiently, especially in scenarios with high read and write throughput.",[42,43,44],"blockquote",{},[11,45,46,47,54],{},"Note: There are some popular packages like ",[48,49,53],"a",{"href":50,"rel":51},"https:\u002F\u002Fgithub.com\u002Fpatrickmn\u002Fgo-cache",[52],"nofollow","go-cache"," that can be used directly. Purpose of this article is to learn on how to implement a working in-memory cache from scratch.",[56,57,58,61,65,79,89,92,120,133,908,915,917,921,932,1984,1987,1989,1993,2001,2011,3168,3179],"ads",{},[59,60],"hr",{},[20,62,64],{"id":63},"implementation","Implementation",[11,66,67,68,72,73,78],{},"Now, let's explore how to implement a basic in-memory cache in Go. Since generics were introduced in ",[69,70,71],"code",{},"Go 1.18"," and it has been some time since generics launched, I highly recommend exploring and learning more about ",[48,74,77],{"href":75,"rel":76},"https:\u002F\u002Fwww.mohitkhare.com\u002Fblog\u002Fgo-generics\u002F",[52],"generics",".",[80,81,83,84,88],"h3",{"id":82},"using-mapstringinterface","Using map",[85,86,87],"span",{},"string","interface",[11,90,91],{},"For a Cache, we need 4 main functions -",[93,94,95,102,108,114],"ul",{},[96,97,98,101],"li",{},[69,99,100],{},"Get()"," - to access value by key",[96,103,104,107],{},[69,105,106],{},"Set()"," - set value to a key",[96,109,110,113],{},[69,111,112],{},"Clear()"," - clears\u002Fresets the cache",[96,115,116,119],{},[69,117,118],{},"Delete()"," - to remove specific key",[11,121,122,123,126,127,132],{},"We create a Cache struct and bind the 4 methods defined above. We use ",[69,124,125],{},"map[string]interface{}"," here since it allows to store the value of any type corresponding to a string key. You can learn more about it ",[48,128,131],{"href":129,"rel":130},"https:\u002F\u002Fbitfieldconsulting.com\u002Fgolang\u002Fmap-string-interface",[52],"here",". Here's the code for same with proper comments.",[134,135,140],"pre",{"className":136,"code":137,"language":138,"meta":139,"style":139},"language-go shiki shiki-themes github-light github-dark","package main\n\nimport (\n    \"fmt\"\n    \"sync\"\n    \"time\"\n)\n\n\u002F\u002F Cache represents an in-memory key-value store.\ntype Cache struct {\n    data map[string]interface{}\n    mu   sync.RWMutex\n}\n\n\u002F\u002F NewCache creates and initializes a new Cache instance.\nfunc NewCache() *Cache {\n    return &Cache{\n        data: make(map[string]interface{}),\n    }\n}\n\n\u002F\u002F Set adds or updates a key-value pair in the cache.\nfunc (c *Cache) Set(key string, value interface{}) {\n    c.mu.Lock()\n    defer c.mu.Unlock()\n    c.data[key] = value\n}\n\n\u002F\u002F Get retrieves the value associated with the given key from the cache.\nfunc (c *Cache) Get(key string) (interface{}, bool) {\n    c.mu.RLock()\n    defer c.mu.RUnlock()\n    value, ok := c.data[key]\n    return value, ok\n}\n\n\u002F\u002F Delete removes a key-value pair from the cache.\nfunc (c *Cache) Delete(key string) {\n    c.mu.Lock()\n    defer c.mu.Unlock()\n    delete(c.data, key)\n}\n\n\u002F\u002F Clear removes all key-value pairs from the cache.\nfunc (c *Cache) Clear() {\n    c.mu.Lock()\n    defer c.mu.Unlock()\n    c.data = make(map[string]interface{})\n}\n\nfunc main() {\n    cache := NewCache()\n\n    \u002F\u002F Adding data to the cache\n    cache.Set(\"key1\", \"value1\")\n    cache.Set(\"key2\", 123)\n\n    \u002F\u002F Retrieving data from the cache\n    if val, ok := cache.Get(\"key1\"); ok {\n        fmt.Println(\"Value for key1:\", val)\n    }\n\n    \u002F\u002F Deleting data from the cache\n    cache.Delete(\"key2\")\n\n    \u002F\u002F Clearing the cache\n    cache.Clear()\n\n    time.Sleep(time.Second) \u002F\u002F Sleep to allow cache operations to complete\n}\n","go","",[69,141,142,154,161,171,184,194,204,210,215,222,237,259,272,278,283,289,309,323,348,354,359,364,370,412,424,438,450,455,460,466,504,514,526,538,546,551,556,562,588,597,608,617,622,627,633,654,663,674,700,705,710,720,732,737,743,763,783,788,794,817,834,839,844,850,863,868,874,883,888,903],{"__ignoreMap":139},[85,143,146,150],{"class":144,"line":145},"line",1,[85,147,149],{"class":148},"szBVR","package",[85,151,153],{"class":152},"sScJk"," main\n",[85,155,157],{"class":144,"line":156},2,[85,158,160],{"emptyLinePlaceholder":159},true,"\n",[85,162,164,167],{"class":144,"line":163},3,[85,165,166],{"class":148},"import",[85,168,170],{"class":169},"sVt8B"," (\n",[85,172,174,178,181],{"class":144,"line":173},4,[85,175,177],{"class":176},"sZZnC","    \"",[85,179,180],{"class":152},"fmt",[85,182,183],{"class":176},"\"\n",[85,185,187,189,192],{"class":144,"line":186},5,[85,188,177],{"class":176},[85,190,191],{"class":152},"sync",[85,193,183],{"class":176},[85,195,197,199,202],{"class":144,"line":196},6,[85,198,177],{"class":176},[85,200,201],{"class":152},"time",[85,203,183],{"class":176},[85,205,207],{"class":144,"line":206},7,[85,208,209],{"class":169},")\n",[85,211,213],{"class":144,"line":212},8,[85,214,160],{"emptyLinePlaceholder":159},[85,216,218],{"class":144,"line":217},9,[85,219,221],{"class":220},"sJ8bj","\u002F\u002F Cache represents an in-memory key-value store.\n",[85,223,225,228,231,234],{"class":144,"line":224},10,[85,226,227],{"class":148},"type",[85,229,230],{"class":152}," Cache",[85,232,233],{"class":148}," struct",[85,235,236],{"class":169}," {\n",[85,238,240,243,246,249,251,254,256],{"class":144,"line":239},11,[85,241,242],{"class":169},"    data ",[85,244,245],{"class":148},"map",[85,247,248],{"class":169},"[",[85,250,87],{"class":148},[85,252,253],{"class":169},"]",[85,255,88],{"class":148},[85,257,258],{"class":169},"{}\n",[85,260,262,265,267,269],{"class":144,"line":261},12,[85,263,264],{"class":169},"    mu   ",[85,266,191],{"class":152},[85,268,78],{"class":169},[85,270,271],{"class":152},"RWMutex\n",[85,273,275],{"class":144,"line":274},13,[85,276,277],{"class":169},"}\n",[85,279,281],{"class":144,"line":280},14,[85,282,160],{"emptyLinePlaceholder":159},[85,284,286],{"class":144,"line":285},15,[85,287,288],{"class":220},"\u002F\u002F NewCache creates and initializes a new Cache instance.\n",[85,290,292,295,298,301,304,307],{"class":144,"line":291},16,[85,293,294],{"class":148},"func",[85,296,297],{"class":152}," NewCache",[85,299,300],{"class":169},"() ",[85,302,303],{"class":148},"*",[85,305,306],{"class":152},"Cache",[85,308,236],{"class":169},[85,310,312,315,318,320],{"class":144,"line":311},17,[85,313,314],{"class":148},"    return",[85,316,317],{"class":148}," &",[85,319,306],{"class":152},[85,321,322],{"class":169},"{\n",[85,324,326,329,332,335,337,339,341,343,345],{"class":144,"line":325},18,[85,327,328],{"class":169},"        data: ",[85,330,331],{"class":152},"make",[85,333,334],{"class":169},"(",[85,336,245],{"class":148},[85,338,248],{"class":169},[85,340,87],{"class":148},[85,342,253],{"class":169},[85,344,88],{"class":148},[85,346,347],{"class":169},"{}),\n",[85,349,351],{"class":144,"line":350},19,[85,352,353],{"class":169},"    }\n",[85,355,357],{"class":144,"line":356},20,[85,358,277],{"class":169},[85,360,362],{"class":144,"line":361},21,[85,363,160],{"emptyLinePlaceholder":159},[85,365,367],{"class":144,"line":366},22,[85,368,369],{"class":220},"\u002F\u002F Set adds or updates a key-value pair in the cache.\n",[85,371,373,375,378,382,384,386,389,392,394,397,400,403,406,409],{"class":144,"line":372},23,[85,374,294],{"class":148},[85,376,377],{"class":169}," (",[85,379,381],{"class":380},"s4XuR","c ",[85,383,303],{"class":148},[85,385,306],{"class":152},[85,387,388],{"class":169},") ",[85,390,391],{"class":152},"Set",[85,393,334],{"class":169},[85,395,396],{"class":380},"key",[85,398,399],{"class":148}," string",[85,401,402],{"class":169},", ",[85,404,405],{"class":380},"value",[85,407,408],{"class":148}," interface",[85,410,411],{"class":169},"{}) {\n",[85,413,415,418,421],{"class":144,"line":414},24,[85,416,417],{"class":169},"    c.mu.",[85,419,420],{"class":152},"Lock",[85,422,423],{"class":169},"()\n",[85,425,427,430,433,436],{"class":144,"line":426},25,[85,428,429],{"class":148},"    defer",[85,431,432],{"class":169}," c.mu.",[85,434,435],{"class":152},"Unlock",[85,437,423],{"class":169},[85,439,441,444,447],{"class":144,"line":440},26,[85,442,443],{"class":169},"    c.data[key] ",[85,445,446],{"class":148},"=",[85,448,449],{"class":169}," value\n",[85,451,453],{"class":144,"line":452},27,[85,454,277],{"class":169},[85,456,458],{"class":144,"line":457},28,[85,459,160],{"emptyLinePlaceholder":159},[85,461,463],{"class":144,"line":462},29,[85,464,465],{"class":220},"\u002F\u002F Get retrieves the value associated with the given key from the cache.\n",[85,467,469,471,473,475,477,479,481,484,486,488,490,493,495,498,501],{"class":144,"line":468},30,[85,470,294],{"class":148},[85,472,377],{"class":169},[85,474,381],{"class":380},[85,476,303],{"class":148},[85,478,306],{"class":152},[85,480,388],{"class":169},[85,482,483],{"class":152},"Get",[85,485,334],{"class":169},[85,487,396],{"class":380},[85,489,399],{"class":148},[85,491,492],{"class":169},") (",[85,494,88],{"class":148},[85,496,497],{"class":169},"{}, ",[85,499,500],{"class":148},"bool",[85,502,503],{"class":169},") {\n",[85,505,507,509,512],{"class":144,"line":506},31,[85,508,417],{"class":169},[85,510,511],{"class":152},"RLock",[85,513,423],{"class":169},[85,515,517,519,521,524],{"class":144,"line":516},32,[85,518,429],{"class":148},[85,520,432],{"class":169},[85,522,523],{"class":152},"RUnlock",[85,525,423],{"class":169},[85,527,529,532,535],{"class":144,"line":528},33,[85,530,531],{"class":169},"    value, ok ",[85,533,534],{"class":148},":=",[85,536,537],{"class":169}," c.data[key]\n",[85,539,541,543],{"class":144,"line":540},34,[85,542,314],{"class":148},[85,544,545],{"class":169}," value, ok\n",[85,547,549],{"class":144,"line":548},35,[85,550,277],{"class":169},[85,552,554],{"class":144,"line":553},36,[85,555,160],{"emptyLinePlaceholder":159},[85,557,559],{"class":144,"line":558},37,[85,560,561],{"class":220},"\u002F\u002F Delete removes a key-value pair from the cache.\n",[85,563,565,567,569,571,573,575,577,580,582,584,586],{"class":144,"line":564},38,[85,566,294],{"class":148},[85,568,377],{"class":169},[85,570,381],{"class":380},[85,572,303],{"class":148},[85,574,306],{"class":152},[85,576,388],{"class":169},[85,578,579],{"class":152},"Delete",[85,581,334],{"class":169},[85,583,396],{"class":380},[85,585,399],{"class":148},[85,587,503],{"class":169},[85,589,591,593,595],{"class":144,"line":590},39,[85,592,417],{"class":169},[85,594,420],{"class":152},[85,596,423],{"class":169},[85,598,600,602,604,606],{"class":144,"line":599},40,[85,601,429],{"class":148},[85,603,432],{"class":169},[85,605,435],{"class":152},[85,607,423],{"class":169},[85,609,611,614],{"class":144,"line":610},41,[85,612,613],{"class":152},"    delete",[85,615,616],{"class":169},"(c.data, key)\n",[85,618,620],{"class":144,"line":619},42,[85,621,277],{"class":169},[85,623,625],{"class":144,"line":624},43,[85,626,160],{"emptyLinePlaceholder":159},[85,628,630],{"class":144,"line":629},44,[85,631,632],{"class":220},"\u002F\u002F Clear removes all key-value pairs from the cache.\n",[85,634,636,638,640,642,644,646,648,651],{"class":144,"line":635},45,[85,637,294],{"class":148},[85,639,377],{"class":169},[85,641,381],{"class":380},[85,643,303],{"class":148},[85,645,306],{"class":152},[85,647,388],{"class":169},[85,649,650],{"class":152},"Clear",[85,652,653],{"class":169},"() {\n",[85,655,657,659,661],{"class":144,"line":656},46,[85,658,417],{"class":169},[85,660,420],{"class":152},[85,662,423],{"class":169},[85,664,666,668,670,672],{"class":144,"line":665},47,[85,667,429],{"class":148},[85,669,432],{"class":169},[85,671,435],{"class":152},[85,673,423],{"class":169},[85,675,677,680,682,685,687,689,691,693,695,697],{"class":144,"line":676},48,[85,678,679],{"class":169},"    c.data ",[85,681,446],{"class":148},[85,683,684],{"class":152}," make",[85,686,334],{"class":169},[85,688,245],{"class":148},[85,690,248],{"class":169},[85,692,87],{"class":148},[85,694,253],{"class":169},[85,696,88],{"class":148},[85,698,699],{"class":169},"{})\n",[85,701,703],{"class":144,"line":702},49,[85,704,277],{"class":169},[85,706,708],{"class":144,"line":707},50,[85,709,160],{"emptyLinePlaceholder":159},[85,711,713,715,718],{"class":144,"line":712},51,[85,714,294],{"class":148},[85,716,717],{"class":152}," main",[85,719,653],{"class":169},[85,721,723,726,728,730],{"class":144,"line":722},52,[85,724,725],{"class":169},"    cache ",[85,727,534],{"class":148},[85,729,297],{"class":152},[85,731,423],{"class":169},[85,733,735],{"class":144,"line":734},53,[85,736,160],{"emptyLinePlaceholder":159},[85,738,740],{"class":144,"line":739},54,[85,741,742],{"class":220},"    \u002F\u002F Adding data to the cache\n",[85,744,746,749,751,753,756,758,761],{"class":144,"line":745},55,[85,747,748],{"class":169},"    cache.",[85,750,391],{"class":152},[85,752,334],{"class":169},[85,754,755],{"class":176},"\"key1\"",[85,757,402],{"class":169},[85,759,760],{"class":176},"\"value1\"",[85,762,209],{"class":169},[85,764,766,768,770,772,775,777,781],{"class":144,"line":765},56,[85,767,748],{"class":169},[85,769,391],{"class":152},[85,771,334],{"class":169},[85,773,774],{"class":176},"\"key2\"",[85,776,402],{"class":169},[85,778,780],{"class":779},"sj4cs","123",[85,782,209],{"class":169},[85,784,786],{"class":144,"line":785},57,[85,787,160],{"emptyLinePlaceholder":159},[85,789,791],{"class":144,"line":790},58,[85,792,793],{"class":220},"    \u002F\u002F Retrieving data from the cache\n",[85,795,797,800,803,805,808,810,812,814],{"class":144,"line":796},59,[85,798,799],{"class":148},"    if",[85,801,802],{"class":169}," val, ok ",[85,804,534],{"class":148},[85,806,807],{"class":169}," cache.",[85,809,483],{"class":152},[85,811,334],{"class":169},[85,813,755],{"class":176},[85,815,816],{"class":169},"); ok {\n",[85,818,820,823,826,828,831],{"class":144,"line":819},60,[85,821,822],{"class":169},"        fmt.",[85,824,825],{"class":152},"Println",[85,827,334],{"class":169},[85,829,830],{"class":176},"\"Value for key1:\"",[85,832,833],{"class":169},", val)\n",[85,835,837],{"class":144,"line":836},61,[85,838,353],{"class":169},[85,840,842],{"class":144,"line":841},62,[85,843,160],{"emptyLinePlaceholder":159},[85,845,847],{"class":144,"line":846},63,[85,848,849],{"class":220},"    \u002F\u002F Deleting data from the cache\n",[85,851,853,855,857,859,861],{"class":144,"line":852},64,[85,854,748],{"class":169},[85,856,579],{"class":152},[85,858,334],{"class":169},[85,860,774],{"class":176},[85,862,209],{"class":169},[85,864,866],{"class":144,"line":865},65,[85,867,160],{"emptyLinePlaceholder":159},[85,869,871],{"class":144,"line":870},66,[85,872,873],{"class":220},"    \u002F\u002F Clearing the cache\n",[85,875,877,879,881],{"class":144,"line":876},67,[85,878,748],{"class":169},[85,880,650],{"class":152},[85,882,423],{"class":169},[85,884,886],{"class":144,"line":885},68,[85,887,160],{"emptyLinePlaceholder":159},[85,889,891,894,897,900],{"class":144,"line":890},69,[85,892,893],{"class":169},"    time.",[85,895,896],{"class":152},"Sleep",[85,898,899],{"class":169},"(time.Second) ",[85,901,902],{"class":220},"\u002F\u002F Sleep to allow cache operations to complete\n",[85,904,906],{"class":144,"line":905},70,[85,907,277],{"class":169},[11,909,910,911,914],{},"Nice! We have a working cache. We used mutex for locking to avoid concurrent access. Feel free to play around with this. If you notice, our cache doesn't support the concept of expiry of keys (TTL). Let's add expiry support to our cache which means after a defined TTL (time to live) the ",[15,912,913],{},"item expires"," and is removed from the cache.",[59,916],{},[80,918,920],{"id":919},"cache-with-expiry-ttl","Cache with Expiry (TTL)",[11,922,923,924,927,928,931],{},"Since each cache entry can have a defined TTL, we create a ",[69,925,926],{},"CacheItem"," struct that contains ",[69,929,930],{},"interface{}"," for storing value and an expiry time field.",[134,933,935],{"className":136,"code":934,"language":138,"meta":139,"style":139},"package main\n\nimport (\n    \"fmt\"\n    \"sync\"\n    \"time\"\n)\n\n\u002F\u002F CacheItem represents an item stored in the cache with its associated TTL.\ntype CacheItem struct {\n    value interface{}\n    expiry time.Time \u002F\u002F TTL for a key\n}\n\n\u002F\u002F Cache represents an in-memory key-value store with expiry support.\ntype Cache struct {\n    data map[string]CacheItem\n    mu   sync.RWMutex\n}\n\n\u002F\u002F NewCache creates and initializes a new Cache instance.\nfunc NewCache() *Cache {\n    return &Cache{\n        data: make(map[string]CacheItem),\n    }\n}\n\n\u002F\u002F Set adds or updates a key-value pair in the cache with the given TTL.\nfunc (c *Cache) Set(key string, value interface{}, ttl time.Duration) {\n    c.mu.Lock()\n    defer c.mu.Unlock()\n\n    c.data[key] = CacheItem{\n        value:  value,\n        expiry: time.Now().Add(ttl),\n    }\n}\n\n\u002F\u002F Get retrieves the value associated with the given key from the cache.\n\u002F\u002F It also checks for expiry and removes expired items.\nfunc (c *Cache) Get(key string) (interface{}, bool) {\n    c.mu.Lock()\n    defer c.mu.Unlock()\n\n    item, ok := c.data[key]\n    if !ok {\n        return nil, false\n    }\n    \u002F\u002F item found - check for expiry\n    if item.expiry.Before(time.Now()) {\n        \u002F\u002F remove entry from cache if time is beyond the expiry\n        delete(c.data, key)\n        return nil, false\n    }\n    return item.value, true\n}\n\n\u002F\u002F Delete removes a key-value pair from the cache.\nfunc (c *Cache) Delete(key string) {\n    c.mu.Lock()\n    defer c.mu.Unlock()\n    delete(c.data, key)\n}\n\n\u002F\u002F Clear removes all key-value pairs from the cache.\nfunc (c *Cache) Clear() {\n    c.mu.Lock()\n    defer c.mu.Unlock()\n    c.data = make(map[string]CacheItem)\n}\n\nfunc main() {\n    cache := NewCache()\n\n    \u002F\u002F Adding data to the cache with a TTL of 2 seconds\n    cache.Set(\"name\", \"mohit\", 2*time.Second)\n    cache.Set(\"weight\", 75, 5*time.Second)\n\n    \u002F\u002F Retrieving data from the cache\n    if val, ok := cache.Get(\"name\"); ok {\n        fmt.Println(\"Value for name:\", val)\n    }\n\n    \u002F\u002F Wait for some time to see expiry in action\n    time.Sleep(3 * time.Second)\n\n    \u002F\u002F Retrieving expired data from the cache\n    if _, ok := cache.Get(\"name\"); !ok {\n        fmt.Println(\"Name key has expired\")\n    }\n\n    \u002F\u002F Retrieving data before expiry\n    if val, ok := cache.Get(\"weight\"); ok {\n        fmt.Println(\"Value for weight before expiry:\", val)\n    }\n\n    \u002F\u002F Wait for some time to see expiry in action\n    time.Sleep(3 * time.Second)\n\n    \u002F\u002F Retrieving expired data from the cache\n    if _, ok := cache.Get(\"weight\"); !ok {\n        fmt.Println(\"Weight key has expired\")\n    }\n\n    \u002F\u002F Deleting data from the cache\n    cache.Set(\"key\", \"val\", 2*time.Second)\n    cache.Delete(\"key\")\n\n    \u002F\u002F Clearing the cache\n    cache.Clear()\n\n    time.Sleep(time.Second) \u002F\u002F Sleep to allow cache operations to complete\n}\n",[69,936,937,943,947,953,961,969,977,981,985,990,1001,1010,1025,1029,1033,1038,1048,1063,1073,1077,1081,1085,1099,1109,1130,1134,1138,1142,1147,1190,1198,1208,1212,1222,1227,1244,1248,1252,1256,1260,1265,1297,1305,1315,1319,1328,1338,1351,1355,1360,1378,1383,1390,1400,1404,1414,1418,1422,1426,1450,1458,1468,1474,1478,1482,1486,1504,1512,1522,1544,1548,1553,1562,1573,1578,1584,1611,1637,1642,1647,1666,1680,1685,1690,1696,1714,1719,1725,1751,1765,1770,1775,1781,1800,1814,1819,1824,1829,1844,1849,1854,1877,1891,1896,1901,1906,1931,1944,1949,1954,1963,1968,1979],{"__ignoreMap":139},[85,938,939,941],{"class":144,"line":145},[85,940,149],{"class":148},[85,942,153],{"class":152},[85,944,945],{"class":144,"line":156},[85,946,160],{"emptyLinePlaceholder":159},[85,948,949,951],{"class":144,"line":163},[85,950,166],{"class":148},[85,952,170],{"class":169},[85,954,955,957,959],{"class":144,"line":173},[85,956,177],{"class":176},[85,958,180],{"class":152},[85,960,183],{"class":176},[85,962,963,965,967],{"class":144,"line":186},[85,964,177],{"class":176},[85,966,191],{"class":152},[85,968,183],{"class":176},[85,970,971,973,975],{"class":144,"line":196},[85,972,177],{"class":176},[85,974,201],{"class":152},[85,976,183],{"class":176},[85,978,979],{"class":144,"line":206},[85,980,209],{"class":169},[85,982,983],{"class":144,"line":212},[85,984,160],{"emptyLinePlaceholder":159},[85,986,987],{"class":144,"line":217},[85,988,989],{"class":220},"\u002F\u002F CacheItem represents an item stored in the cache with its associated TTL.\n",[85,991,992,994,997,999],{"class":144,"line":224},[85,993,227],{"class":148},[85,995,996],{"class":152}," CacheItem",[85,998,233],{"class":148},[85,1000,236],{"class":169},[85,1002,1003,1006,1008],{"class":144,"line":239},[85,1004,1005],{"class":169},"    value ",[85,1007,88],{"class":148},[85,1009,258],{"class":169},[85,1011,1012,1015,1017,1019,1022],{"class":144,"line":261},[85,1013,1014],{"class":169},"    expiry ",[85,1016,201],{"class":152},[85,1018,78],{"class":169},[85,1020,1021],{"class":152},"Time",[85,1023,1024],{"class":220}," \u002F\u002F TTL for a key\n",[85,1026,1027],{"class":144,"line":274},[85,1028,277],{"class":169},[85,1030,1031],{"class":144,"line":280},[85,1032,160],{"emptyLinePlaceholder":159},[85,1034,1035],{"class":144,"line":285},[85,1036,1037],{"class":220},"\u002F\u002F Cache represents an in-memory key-value store with expiry support.\n",[85,1039,1040,1042,1044,1046],{"class":144,"line":291},[85,1041,227],{"class":148},[85,1043,230],{"class":152},[85,1045,233],{"class":148},[85,1047,236],{"class":169},[85,1049,1050,1052,1054,1056,1058,1060],{"class":144,"line":311},[85,1051,242],{"class":169},[85,1053,245],{"class":148},[85,1055,248],{"class":169},[85,1057,87],{"class":148},[85,1059,253],{"class":169},[85,1061,1062],{"class":152},"CacheItem\n",[85,1064,1065,1067,1069,1071],{"class":144,"line":325},[85,1066,264],{"class":169},[85,1068,191],{"class":152},[85,1070,78],{"class":169},[85,1072,271],{"class":152},[85,1074,1075],{"class":144,"line":350},[85,1076,277],{"class":169},[85,1078,1079],{"class":144,"line":356},[85,1080,160],{"emptyLinePlaceholder":159},[85,1082,1083],{"class":144,"line":361},[85,1084,288],{"class":220},[85,1086,1087,1089,1091,1093,1095,1097],{"class":144,"line":366},[85,1088,294],{"class":148},[85,1090,297],{"class":152},[85,1092,300],{"class":169},[85,1094,303],{"class":148},[85,1096,306],{"class":152},[85,1098,236],{"class":169},[85,1100,1101,1103,1105,1107],{"class":144,"line":372},[85,1102,314],{"class":148},[85,1104,317],{"class":148},[85,1106,306],{"class":152},[85,1108,322],{"class":169},[85,1110,1111,1113,1115,1117,1119,1121,1123,1125,1127],{"class":144,"line":414},[85,1112,328],{"class":169},[85,1114,331],{"class":152},[85,1116,334],{"class":169},[85,1118,245],{"class":148},[85,1120,248],{"class":169},[85,1122,87],{"class":148},[85,1124,253],{"class":169},[85,1126,926],{"class":152},[85,1128,1129],{"class":169},"),\n",[85,1131,1132],{"class":144,"line":426},[85,1133,353],{"class":169},[85,1135,1136],{"class":144,"line":440},[85,1137,277],{"class":169},[85,1139,1140],{"class":144,"line":452},[85,1141,160],{"emptyLinePlaceholder":159},[85,1143,1144],{"class":144,"line":457},[85,1145,1146],{"class":220},"\u002F\u002F Set adds or updates a key-value pair in the cache with the given TTL.\n",[85,1148,1149,1151,1153,1155,1157,1159,1161,1163,1165,1167,1169,1171,1173,1175,1177,1180,1183,1185,1188],{"class":144,"line":462},[85,1150,294],{"class":148},[85,1152,377],{"class":169},[85,1154,381],{"class":380},[85,1156,303],{"class":148},[85,1158,306],{"class":152},[85,1160,388],{"class":169},[85,1162,391],{"class":152},[85,1164,334],{"class":169},[85,1166,396],{"class":380},[85,1168,399],{"class":148},[85,1170,402],{"class":169},[85,1172,405],{"class":380},[85,1174,408],{"class":148},[85,1176,497],{"class":169},[85,1178,1179],{"class":380},"ttl",[85,1181,1182],{"class":152}," time",[85,1184,78],{"class":169},[85,1186,1187],{"class":152},"Duration",[85,1189,503],{"class":169},[85,1191,1192,1194,1196],{"class":144,"line":468},[85,1193,417],{"class":169},[85,1195,420],{"class":152},[85,1197,423],{"class":169},[85,1199,1200,1202,1204,1206],{"class":144,"line":506},[85,1201,429],{"class":148},[85,1203,432],{"class":169},[85,1205,435],{"class":152},[85,1207,423],{"class":169},[85,1209,1210],{"class":144,"line":516},[85,1211,160],{"emptyLinePlaceholder":159},[85,1213,1214,1216,1218,1220],{"class":144,"line":528},[85,1215,443],{"class":169},[85,1217,446],{"class":148},[85,1219,996],{"class":152},[85,1221,322],{"class":169},[85,1223,1224],{"class":144,"line":540},[85,1225,1226],{"class":169},"        value:  value,\n",[85,1228,1229,1232,1235,1238,1241],{"class":144,"line":548},[85,1230,1231],{"class":169},"        expiry: time.",[85,1233,1234],{"class":152},"Now",[85,1236,1237],{"class":169},"().",[85,1239,1240],{"class":152},"Add",[85,1242,1243],{"class":169},"(ttl),\n",[85,1245,1246],{"class":144,"line":553},[85,1247,353],{"class":169},[85,1249,1250],{"class":144,"line":558},[85,1251,277],{"class":169},[85,1253,1254],{"class":144,"line":564},[85,1255,160],{"emptyLinePlaceholder":159},[85,1257,1258],{"class":144,"line":590},[85,1259,465],{"class":220},[85,1261,1262],{"class":144,"line":599},[85,1263,1264],{"class":220},"\u002F\u002F It also checks for expiry and removes expired items.\n",[85,1266,1267,1269,1271,1273,1275,1277,1279,1281,1283,1285,1287,1289,1291,1293,1295],{"class":144,"line":610},[85,1268,294],{"class":148},[85,1270,377],{"class":169},[85,1272,381],{"class":380},[85,1274,303],{"class":148},[85,1276,306],{"class":152},[85,1278,388],{"class":169},[85,1280,483],{"class":152},[85,1282,334],{"class":169},[85,1284,396],{"class":380},[85,1286,399],{"class":148},[85,1288,492],{"class":169},[85,1290,88],{"class":148},[85,1292,497],{"class":169},[85,1294,500],{"class":148},[85,1296,503],{"class":169},[85,1298,1299,1301,1303],{"class":144,"line":619},[85,1300,417],{"class":169},[85,1302,420],{"class":152},[85,1304,423],{"class":169},[85,1306,1307,1309,1311,1313],{"class":144,"line":624},[85,1308,429],{"class":148},[85,1310,432],{"class":169},[85,1312,435],{"class":152},[85,1314,423],{"class":169},[85,1316,1317],{"class":144,"line":629},[85,1318,160],{"emptyLinePlaceholder":159},[85,1320,1321,1324,1326],{"class":144,"line":635},[85,1322,1323],{"class":169},"    item, ok ",[85,1325,534],{"class":148},[85,1327,537],{"class":169},[85,1329,1330,1332,1335],{"class":144,"line":656},[85,1331,799],{"class":148},[85,1333,1334],{"class":148}," !",[85,1336,1337],{"class":169},"ok {\n",[85,1339,1340,1343,1346,1348],{"class":144,"line":665},[85,1341,1342],{"class":148},"        return",[85,1344,1345],{"class":779}," nil",[85,1347,402],{"class":169},[85,1349,1350],{"class":779},"false\n",[85,1352,1353],{"class":144,"line":676},[85,1354,353],{"class":169},[85,1356,1357],{"class":144,"line":702},[85,1358,1359],{"class":220},"    \u002F\u002F item found - check for expiry\n",[85,1361,1362,1364,1367,1370,1373,1375],{"class":144,"line":707},[85,1363,799],{"class":148},[85,1365,1366],{"class":169}," item.expiry.",[85,1368,1369],{"class":152},"Before",[85,1371,1372],{"class":169},"(time.",[85,1374,1234],{"class":152},[85,1376,1377],{"class":169},"()) {\n",[85,1379,1380],{"class":144,"line":712},[85,1381,1382],{"class":220},"        \u002F\u002F remove entry from cache if time is beyond the expiry\n",[85,1384,1385,1388],{"class":144,"line":722},[85,1386,1387],{"class":152},"        delete",[85,1389,616],{"class":169},[85,1391,1392,1394,1396,1398],{"class":144,"line":734},[85,1393,1342],{"class":148},[85,1395,1345],{"class":779},[85,1397,402],{"class":169},[85,1399,1350],{"class":779},[85,1401,1402],{"class":144,"line":739},[85,1403,353],{"class":169},[85,1405,1406,1408,1411],{"class":144,"line":745},[85,1407,314],{"class":148},[85,1409,1410],{"class":169}," item.value, ",[85,1412,1413],{"class":779},"true\n",[85,1415,1416],{"class":144,"line":765},[85,1417,277],{"class":169},[85,1419,1420],{"class":144,"line":785},[85,1421,160],{"emptyLinePlaceholder":159},[85,1423,1424],{"class":144,"line":790},[85,1425,561],{"class":220},[85,1427,1428,1430,1432,1434,1436,1438,1440,1442,1444,1446,1448],{"class":144,"line":796},[85,1429,294],{"class":148},[85,1431,377],{"class":169},[85,1433,381],{"class":380},[85,1435,303],{"class":148},[85,1437,306],{"class":152},[85,1439,388],{"class":169},[85,1441,579],{"class":152},[85,1443,334],{"class":169},[85,1445,396],{"class":380},[85,1447,399],{"class":148},[85,1449,503],{"class":169},[85,1451,1452,1454,1456],{"class":144,"line":819},[85,1453,417],{"class":169},[85,1455,420],{"class":152},[85,1457,423],{"class":169},[85,1459,1460,1462,1464,1466],{"class":144,"line":836},[85,1461,429],{"class":148},[85,1463,432],{"class":169},[85,1465,435],{"class":152},[85,1467,423],{"class":169},[85,1469,1470,1472],{"class":144,"line":841},[85,1471,613],{"class":152},[85,1473,616],{"class":169},[85,1475,1476],{"class":144,"line":846},[85,1477,277],{"class":169},[85,1479,1480],{"class":144,"line":852},[85,1481,160],{"emptyLinePlaceholder":159},[85,1483,1484],{"class":144,"line":865},[85,1485,632],{"class":220},[85,1487,1488,1490,1492,1494,1496,1498,1500,1502],{"class":144,"line":870},[85,1489,294],{"class":148},[85,1491,377],{"class":169},[85,1493,381],{"class":380},[85,1495,303],{"class":148},[85,1497,306],{"class":152},[85,1499,388],{"class":169},[85,1501,650],{"class":152},[85,1503,653],{"class":169},[85,1505,1506,1508,1510],{"class":144,"line":876},[85,1507,417],{"class":169},[85,1509,420],{"class":152},[85,1511,423],{"class":169},[85,1513,1514,1516,1518,1520],{"class":144,"line":885},[85,1515,429],{"class":148},[85,1517,432],{"class":169},[85,1519,435],{"class":152},[85,1521,423],{"class":169},[85,1523,1524,1526,1528,1530,1532,1534,1536,1538,1540,1542],{"class":144,"line":890},[85,1525,679],{"class":169},[85,1527,446],{"class":148},[85,1529,684],{"class":152},[85,1531,334],{"class":169},[85,1533,245],{"class":148},[85,1535,248],{"class":169},[85,1537,87],{"class":148},[85,1539,253],{"class":169},[85,1541,926],{"class":152},[85,1543,209],{"class":169},[85,1545,1546],{"class":144,"line":905},[85,1547,277],{"class":169},[85,1549,1551],{"class":144,"line":1550},71,[85,1552,160],{"emptyLinePlaceholder":159},[85,1554,1556,1558,1560],{"class":144,"line":1555},72,[85,1557,294],{"class":148},[85,1559,717],{"class":152},[85,1561,653],{"class":169},[85,1563,1565,1567,1569,1571],{"class":144,"line":1564},73,[85,1566,725],{"class":169},[85,1568,534],{"class":148},[85,1570,297],{"class":152},[85,1572,423],{"class":169},[85,1574,1576],{"class":144,"line":1575},74,[85,1577,160],{"emptyLinePlaceholder":159},[85,1579,1581],{"class":144,"line":1580},75,[85,1582,1583],{"class":220},"    \u002F\u002F Adding data to the cache with a TTL of 2 seconds\n",[85,1585,1587,1589,1591,1593,1596,1598,1601,1603,1606,1608],{"class":144,"line":1586},76,[85,1588,748],{"class":169},[85,1590,391],{"class":152},[85,1592,334],{"class":169},[85,1594,1595],{"class":176},"\"name\"",[85,1597,402],{"class":169},[85,1599,1600],{"class":176},"\"mohit\"",[85,1602,402],{"class":169},[85,1604,1605],{"class":779},"2",[85,1607,303],{"class":148},[85,1609,1610],{"class":169},"time.Second)\n",[85,1612,1614,1616,1618,1620,1623,1625,1628,1630,1633,1635],{"class":144,"line":1613},77,[85,1615,748],{"class":169},[85,1617,391],{"class":152},[85,1619,334],{"class":169},[85,1621,1622],{"class":176},"\"weight\"",[85,1624,402],{"class":169},[85,1626,1627],{"class":779},"75",[85,1629,402],{"class":169},[85,1631,1632],{"class":779},"5",[85,1634,303],{"class":148},[85,1636,1610],{"class":169},[85,1638,1640],{"class":144,"line":1639},78,[85,1641,160],{"emptyLinePlaceholder":159},[85,1643,1645],{"class":144,"line":1644},79,[85,1646,793],{"class":220},[85,1648,1650,1652,1654,1656,1658,1660,1662,1664],{"class":144,"line":1649},80,[85,1651,799],{"class":148},[85,1653,802],{"class":169},[85,1655,534],{"class":148},[85,1657,807],{"class":169},[85,1659,483],{"class":152},[85,1661,334],{"class":169},[85,1663,1595],{"class":176},[85,1665,816],{"class":169},[85,1667,1669,1671,1673,1675,1678],{"class":144,"line":1668},81,[85,1670,822],{"class":169},[85,1672,825],{"class":152},[85,1674,334],{"class":169},[85,1676,1677],{"class":176},"\"Value for name:\"",[85,1679,833],{"class":169},[85,1681,1683],{"class":144,"line":1682},82,[85,1684,353],{"class":169},[85,1686,1688],{"class":144,"line":1687},83,[85,1689,160],{"emptyLinePlaceholder":159},[85,1691,1693],{"class":144,"line":1692},84,[85,1694,1695],{"class":220},"    \u002F\u002F Wait for some time to see expiry in action\n",[85,1697,1699,1701,1703,1705,1708,1711],{"class":144,"line":1698},85,[85,1700,893],{"class":169},[85,1702,896],{"class":152},[85,1704,334],{"class":169},[85,1706,1707],{"class":779},"3",[85,1709,1710],{"class":148}," *",[85,1712,1713],{"class":169}," time.Second)\n",[85,1715,1717],{"class":144,"line":1716},86,[85,1718,160],{"emptyLinePlaceholder":159},[85,1720,1722],{"class":144,"line":1721},87,[85,1723,1724],{"class":220},"    \u002F\u002F Retrieving expired data from the cache\n",[85,1726,1728,1730,1733,1735,1737,1739,1741,1743,1746,1749],{"class":144,"line":1727},88,[85,1729,799],{"class":148},[85,1731,1732],{"class":169}," _, ok ",[85,1734,534],{"class":148},[85,1736,807],{"class":169},[85,1738,483],{"class":152},[85,1740,334],{"class":169},[85,1742,1595],{"class":176},[85,1744,1745],{"class":169},"); ",[85,1747,1748],{"class":148},"!",[85,1750,1337],{"class":169},[85,1752,1754,1756,1758,1760,1763],{"class":144,"line":1753},89,[85,1755,822],{"class":169},[85,1757,825],{"class":152},[85,1759,334],{"class":169},[85,1761,1762],{"class":176},"\"Name key has expired\"",[85,1764,209],{"class":169},[85,1766,1768],{"class":144,"line":1767},90,[85,1769,353],{"class":169},[85,1771,1773],{"class":144,"line":1772},91,[85,1774,160],{"emptyLinePlaceholder":159},[85,1776,1778],{"class":144,"line":1777},92,[85,1779,1780],{"class":220},"    \u002F\u002F Retrieving data before expiry\n",[85,1782,1784,1786,1788,1790,1792,1794,1796,1798],{"class":144,"line":1783},93,[85,1785,799],{"class":148},[85,1787,802],{"class":169},[85,1789,534],{"class":148},[85,1791,807],{"class":169},[85,1793,483],{"class":152},[85,1795,334],{"class":169},[85,1797,1622],{"class":176},[85,1799,816],{"class":169},[85,1801,1803,1805,1807,1809,1812],{"class":144,"line":1802},94,[85,1804,822],{"class":169},[85,1806,825],{"class":152},[85,1808,334],{"class":169},[85,1810,1811],{"class":176},"\"Value for weight before expiry:\"",[85,1813,833],{"class":169},[85,1815,1817],{"class":144,"line":1816},95,[85,1818,353],{"class":169},[85,1820,1822],{"class":144,"line":1821},96,[85,1823,160],{"emptyLinePlaceholder":159},[85,1825,1827],{"class":144,"line":1826},97,[85,1828,1695],{"class":220},[85,1830,1832,1834,1836,1838,1840,1842],{"class":144,"line":1831},98,[85,1833,893],{"class":169},[85,1835,896],{"class":152},[85,1837,334],{"class":169},[85,1839,1707],{"class":779},[85,1841,1710],{"class":148},[85,1843,1713],{"class":169},[85,1845,1847],{"class":144,"line":1846},99,[85,1848,160],{"emptyLinePlaceholder":159},[85,1850,1852],{"class":144,"line":1851},100,[85,1853,1724],{"class":220},[85,1855,1857,1859,1861,1863,1865,1867,1869,1871,1873,1875],{"class":144,"line":1856},101,[85,1858,799],{"class":148},[85,1860,1732],{"class":169},[85,1862,534],{"class":148},[85,1864,807],{"class":169},[85,1866,483],{"class":152},[85,1868,334],{"class":169},[85,1870,1622],{"class":176},[85,1872,1745],{"class":169},[85,1874,1748],{"class":148},[85,1876,1337],{"class":169},[85,1878,1880,1882,1884,1886,1889],{"class":144,"line":1879},102,[85,1881,822],{"class":169},[85,1883,825],{"class":152},[85,1885,334],{"class":169},[85,1887,1888],{"class":176},"\"Weight key has expired\"",[85,1890,209],{"class":169},[85,1892,1894],{"class":144,"line":1893},103,[85,1895,353],{"class":169},[85,1897,1899],{"class":144,"line":1898},104,[85,1900,160],{"emptyLinePlaceholder":159},[85,1902,1904],{"class":144,"line":1903},105,[85,1905,849],{"class":220},[85,1907,1909,1911,1913,1915,1918,1920,1923,1925,1927,1929],{"class":144,"line":1908},106,[85,1910,748],{"class":169},[85,1912,391],{"class":152},[85,1914,334],{"class":169},[85,1916,1917],{"class":176},"\"key\"",[85,1919,402],{"class":169},[85,1921,1922],{"class":176},"\"val\"",[85,1924,402],{"class":169},[85,1926,1605],{"class":779},[85,1928,303],{"class":148},[85,1930,1610],{"class":169},[85,1932,1934,1936,1938,1940,1942],{"class":144,"line":1933},107,[85,1935,748],{"class":169},[85,1937,579],{"class":152},[85,1939,334],{"class":169},[85,1941,1917],{"class":176},[85,1943,209],{"class":169},[85,1945,1947],{"class":144,"line":1946},108,[85,1948,160],{"emptyLinePlaceholder":159},[85,1950,1952],{"class":144,"line":1951},109,[85,1953,873],{"class":220},[85,1955,1957,1959,1961],{"class":144,"line":1956},110,[85,1958,748],{"class":169},[85,1960,650],{"class":152},[85,1962,423],{"class":169},[85,1964,1966],{"class":144,"line":1965},111,[85,1967,160],{"emptyLinePlaceholder":159},[85,1969,1971,1973,1975,1977],{"class":144,"line":1970},112,[85,1972,893],{"class":169},[85,1974,896],{"class":152},[85,1976,899],{"class":169},[85,1978,902],{"class":220},[85,1980,1982],{"class":144,"line":1981},113,[85,1983,277],{"class":169},[11,1985,1986],{},"With this expiry support, our cache implementation becomes more versatile and suitable for a wider range of caching scenarios.",[59,1988],{},[80,1990,1992],{"id":1991},"in-memory-cache-using-generics","In-memory cache using Generics",[11,1994,1995,1996,2000],{},"Before proceeding with implementation, if you are to generics, then I recommend to start with the ",[48,1997,1999],{"href":75,"rel":1998},[52],"basics of generics"," and then come back and learn to implement this.",[11,2002,2003,2004,2006,2007,2010],{},"Logically it's similar, only instead of using ",[69,2005,930],{}," we leverage generics using ",[69,2008,2009],{},"any"," type. Here's the code for generics implementation.",[134,2012,2014],{"className":136,"code":2013,"language":138,"meta":139,"style":139},"package main\n\nimport (\n    \"fmt\"\n    \"sync\"\n    \"time\"\n)\n\n\u002F\u002F Requires go >= 1.18\n\u002F\u002F This implementation uses Go Generics\n\n\u002F\u002F CacheItem represents an item stored in the cache with its associated TTL.\ntype CacheItem[T any] struct {\n    value  T\n    expiry time.Time\n}\n\n\u002F\u002F Cache represents an in-memory key-value store with expiry support.\ntype Cache[K comparable, T any] struct {\n    data map[K]CacheItem[T] \u002F\u002F stores cache items\n    mu sync.RWMutex \u002F\u002F managing concurrent access\n}\n\n\u002F\u002F NewCache creates and initializes a new Cache instance.\nfunc NewCache[K comparable, T any]() *Cache[K, T] {\n    return &Cache[K, T]{\n        data: make(map[K]CacheItem[T]),\n    }\n}\n\n\u002F\u002F Set adds or updates a key-value pair in the cache with the given TTL.\nfunc (c *Cache[K, T]) Set(key K, value T, ttl time.Duration) {\n    c.mu.Lock()\n    defer c.mu.Unlock()\n\n    c.data[key] = CacheItem[T]{\n        value:  value,\n        expiry: time.Now().Add(ttl),\n    }\n}\n\nfunc zeroVal[T any]() T {\n    var zero T\n    return zero\n}\n\n\u002F\u002F Get retrieves the value associated with the given key from the cache.\n\u002F\u002F It also checks for expiry and removes expired items.\nfunc (c *Cache[K, T]) Get(key K) (T, bool) {\n    c.mu.Lock()\n    defer c.mu.Unlock()\n    item, ok := c.data[key]\n    if !ok {\n        return zeroVal[T](), false\n    }\n    \u002F\u002F item found - check for expiry\n    if item.expiry.Before(time.Now()) {\n        \u002F\u002F remove entry from cache if time is beyond the expiry\n        delete(c.data, key)\n        return zeroVal[T](), false\n    }\n    return item.value, true\n}\n\n\u002F\u002F Delete removes a key-value pair from the cache.\nfunc (c *Cache[K, T]) Delete(key K) {\n    c.mu.Lock()\n    defer c.mu.Unlock()\n    delete(c.data, key)\n}\n\n\u002F\u002F Clear removes all key-value pairs from the cache.\nfunc (c *Cache[K, T]) Clear() {\n    c.mu.Lock()\n    defer c.mu.Unlock()\n    c.data = make(map[K]CacheItem[T])\n}\n\nfunc main() {\n    cache := NewCache[string, int]()\n\n    \u002F\u002F Adding data to the cache with a TTL of 2 seconds\n    cache.Set(\"height\", 175, 2*time.Second)\n    cache.Set(\"weight\", 75, 5*time.Second)\n\n    \u002F\u002F Retrieving data from the cache\n    if val, ok := cache.Get(\"height\"); ok {\n        fmt.Println(\"Value for height:\", val)\n    }\n\n    \u002F\u002F Wait for some time to see expiry in action\n    time.Sleep(3 * time.Second)\n\n    \u002F\u002F Retrieving expired data from the cache\n    if _, ok := cache.Get(\"height\"); !ok {\n        fmt.Println(\"height key has expired\")\n    }\n\n    \u002F\u002F Retrieving data before expiry\n    if val, ok := cache.Get(\"weight\"); ok {\n        fmt.Println(\"Value for weight before expiry:\", val)\n    }\n\n    \u002F\u002F Wait for some time to see expiry in action\n    time.Sleep(3 * time.Second)\n\n    \u002F\u002F Retrieving expired data from the cache\n    if _, ok := cache.Get(\"weight\"); !ok {\n        fmt.Println(\"Weight key has expired\")\n    }\n\n    \u002F\u002F Deleting data from the cache\n    cache.Set(\"key\", 1, 2*time.Second)\n    cache.Delete(\"key\")\n\n    \u002F\u002F Clearing the cache\n    cache.Clear()\n\n    time.Sleep(time.Second) \u002F\u002F Sleep to allow cache operations to complete\n}\n",[69,2015,2016,2022,2026,2032,2040,2048,2056,2060,2064,2069,2074,2078,2082,2104,2112,2123,2127,2131,2135,2161,2184,2199,2203,2207,2211,2247,2266,2291,2295,2299,2303,2307,2358,2366,2376,2380,2394,2398,2410,2414,2418,2422,2441,2451,2458,2462,2466,2470,2474,2514,2522,2532,2540,2548,2563,2567,2571,2585,2589,2595,2609,2613,2621,2625,2629,2633,2665,2673,2683,2689,2693,2697,2701,2727,2735,2745,2772,2776,2780,2788,2808,2812,2816,2840,2862,2866,2870,2888,2901,2905,2909,2913,2927,2931,2935,2957,2970,2974,2978,2982,3000,3012,3016,3020,3024,3038,3042,3046,3068,3080,3084,3088,3092,3115,3128,3133,3138,3147,3152,3163],{"__ignoreMap":139},[85,2017,2018,2020],{"class":144,"line":145},[85,2019,149],{"class":148},[85,2021,153],{"class":152},[85,2023,2024],{"class":144,"line":156},[85,2025,160],{"emptyLinePlaceholder":159},[85,2027,2028,2030],{"class":144,"line":163},[85,2029,166],{"class":148},[85,2031,170],{"class":169},[85,2033,2034,2036,2038],{"class":144,"line":173},[85,2035,177],{"class":176},[85,2037,180],{"class":152},[85,2039,183],{"class":176},[85,2041,2042,2044,2046],{"class":144,"line":186},[85,2043,177],{"class":176},[85,2045,191],{"class":152},[85,2047,183],{"class":176},[85,2049,2050,2052,2054],{"class":144,"line":196},[85,2051,177],{"class":176},[85,2053,201],{"class":152},[85,2055,183],{"class":176},[85,2057,2058],{"class":144,"line":206},[85,2059,209],{"class":169},[85,2061,2062],{"class":144,"line":212},[85,2063,160],{"emptyLinePlaceholder":159},[85,2065,2066],{"class":144,"line":217},[85,2067,2068],{"class":220},"\u002F\u002F Requires go >= 1.18\n",[85,2070,2071],{"class":144,"line":224},[85,2072,2073],{"class":220},"\u002F\u002F This implementation uses Go Generics\n",[85,2075,2076],{"class":144,"line":239},[85,2077,160],{"emptyLinePlaceholder":159},[85,2079,2080],{"class":144,"line":261},[85,2081,989],{"class":220},[85,2083,2084,2086,2088,2090,2093,2096,2099,2102],{"class":144,"line":274},[85,2085,227],{"class":148},[85,2087,996],{"class":152},[85,2089,248],{"class":169},[85,2091,2092],{"class":380},"T",[85,2094,2095],{"class":152}," any",[85,2097,2098],{"class":169},"] ",[85,2100,2101],{"class":148},"struct",[85,2103,236],{"class":169},[85,2105,2106,2109],{"class":144,"line":280},[85,2107,2108],{"class":169},"    value  ",[85,2110,2111],{"class":152},"T\n",[85,2113,2114,2116,2118,2120],{"class":144,"line":285},[85,2115,1014],{"class":169},[85,2117,201],{"class":152},[85,2119,78],{"class":169},[85,2121,2122],{"class":152},"Time\n",[85,2124,2125],{"class":144,"line":291},[85,2126,277],{"class":169},[85,2128,2129],{"class":144,"line":311},[85,2130,160],{"emptyLinePlaceholder":159},[85,2132,2133],{"class":144,"line":325},[85,2134,1037],{"class":220},[85,2136,2137,2139,2141,2143,2146,2149,2151,2153,2155,2157,2159],{"class":144,"line":350},[85,2138,227],{"class":148},[85,2140,230],{"class":152},[85,2142,248],{"class":169},[85,2144,2145],{"class":380},"K",[85,2147,2148],{"class":152}," comparable",[85,2150,402],{"class":169},[85,2152,2092],{"class":380},[85,2154,2095],{"class":152},[85,2156,2098],{"class":169},[85,2158,2101],{"class":148},[85,2160,236],{"class":169},[85,2162,2163,2165,2167,2169,2171,2173,2175,2177,2179,2181],{"class":144,"line":356},[85,2164,242],{"class":169},[85,2166,245],{"class":148},[85,2168,248],{"class":169},[85,2170,2145],{"class":152},[85,2172,253],{"class":169},[85,2174,926],{"class":152},[85,2176,248],{"class":169},[85,2178,2092],{"class":152},[85,2180,2098],{"class":169},[85,2182,2183],{"class":220},"\u002F\u002F stores cache items\n",[85,2185,2186,2189,2191,2193,2196],{"class":144,"line":361},[85,2187,2188],{"class":169},"    mu ",[85,2190,191],{"class":152},[85,2192,78],{"class":169},[85,2194,2195],{"class":152},"RWMutex",[85,2197,2198],{"class":220}," \u002F\u002F managing concurrent access\n",[85,2200,2201],{"class":144,"line":366},[85,2202,277],{"class":169},[85,2204,2205],{"class":144,"line":372},[85,2206,160],{"emptyLinePlaceholder":159},[85,2208,2209],{"class":144,"line":414},[85,2210,288],{"class":220},[85,2212,2213,2215,2217,2219,2221,2223,2225,2227,2229,2232,2234,2236,2238,2240,2242,2244],{"class":144,"line":426},[85,2214,294],{"class":148},[85,2216,297],{"class":152},[85,2218,248],{"class":169},[85,2220,2145],{"class":380},[85,2222,2148],{"class":152},[85,2224,402],{"class":169},[85,2226,2092],{"class":380},[85,2228,2095],{"class":152},[85,2230,2231],{"class":169},"]() ",[85,2233,303],{"class":148},[85,2235,306],{"class":152},[85,2237,248],{"class":169},[85,2239,2145],{"class":152},[85,2241,402],{"class":169},[85,2243,2092],{"class":152},[85,2245,2246],{"class":169},"] {\n",[85,2248,2249,2251,2253,2255,2257,2259,2261,2263],{"class":144,"line":440},[85,2250,314],{"class":148},[85,2252,317],{"class":148},[85,2254,306],{"class":152},[85,2256,248],{"class":169},[85,2258,2145],{"class":152},[85,2260,402],{"class":169},[85,2262,2092],{"class":152},[85,2264,2265],{"class":169},"]{\n",[85,2267,2268,2270,2272,2274,2276,2278,2280,2282,2284,2286,2288],{"class":144,"line":452},[85,2269,328],{"class":169},[85,2271,331],{"class":152},[85,2273,334],{"class":169},[85,2275,245],{"class":148},[85,2277,248],{"class":169},[85,2279,2145],{"class":152},[85,2281,253],{"class":169},[85,2283,926],{"class":152},[85,2285,248],{"class":169},[85,2287,2092],{"class":152},[85,2289,2290],{"class":169},"]),\n",[85,2292,2293],{"class":144,"line":457},[85,2294,353],{"class":169},[85,2296,2297],{"class":144,"line":462},[85,2298,277],{"class":169},[85,2300,2301],{"class":144,"line":468},[85,2302,160],{"emptyLinePlaceholder":159},[85,2304,2305],{"class":144,"line":506},[85,2306,1146],{"class":220},[85,2308,2309,2311,2313,2315,2317,2319,2321,2323,2325,2327,2330,2332,2334,2336,2339,2341,2343,2346,2348,2350,2352,2354,2356],{"class":144,"line":516},[85,2310,294],{"class":148},[85,2312,377],{"class":169},[85,2314,381],{"class":380},[85,2316,303],{"class":148},[85,2318,306],{"class":152},[85,2320,248],{"class":169},[85,2322,2145],{"class":152},[85,2324,402],{"class":169},[85,2326,2092],{"class":152},[85,2328,2329],{"class":169},"]) ",[85,2331,391],{"class":152},[85,2333,334],{"class":169},[85,2335,396],{"class":380},[85,2337,2338],{"class":152}," K",[85,2340,402],{"class":169},[85,2342,405],{"class":380},[85,2344,2345],{"class":152}," T",[85,2347,402],{"class":169},[85,2349,1179],{"class":380},[85,2351,1182],{"class":152},[85,2353,78],{"class":169},[85,2355,1187],{"class":152},[85,2357,503],{"class":169},[85,2359,2360,2362,2364],{"class":144,"line":528},[85,2361,417],{"class":169},[85,2363,420],{"class":152},[85,2365,423],{"class":169},[85,2367,2368,2370,2372,2374],{"class":144,"line":540},[85,2369,429],{"class":148},[85,2371,432],{"class":169},[85,2373,435],{"class":152},[85,2375,423],{"class":169},[85,2377,2378],{"class":144,"line":548},[85,2379,160],{"emptyLinePlaceholder":159},[85,2381,2382,2384,2386,2388,2390,2392],{"class":144,"line":553},[85,2383,443],{"class":169},[85,2385,446],{"class":148},[85,2387,996],{"class":152},[85,2389,248],{"class":169},[85,2391,2092],{"class":152},[85,2393,2265],{"class":169},[85,2395,2396],{"class":144,"line":558},[85,2397,1226],{"class":169},[85,2399,2400,2402,2404,2406,2408],{"class":144,"line":564},[85,2401,1231],{"class":169},[85,2403,1234],{"class":152},[85,2405,1237],{"class":169},[85,2407,1240],{"class":152},[85,2409,1243],{"class":169},[85,2411,2412],{"class":144,"line":590},[85,2413,353],{"class":169},[85,2415,2416],{"class":144,"line":599},[85,2417,277],{"class":169},[85,2419,2420],{"class":144,"line":610},[85,2421,160],{"emptyLinePlaceholder":159},[85,2423,2424,2426,2429,2431,2433,2435,2437,2439],{"class":144,"line":619},[85,2425,294],{"class":148},[85,2427,2428],{"class":152}," zeroVal",[85,2430,248],{"class":169},[85,2432,2092],{"class":380},[85,2434,2095],{"class":152},[85,2436,2231],{"class":169},[85,2438,2092],{"class":152},[85,2440,236],{"class":169},[85,2442,2443,2446,2449],{"class":144,"line":624},[85,2444,2445],{"class":148},"    var",[85,2447,2448],{"class":169}," zero ",[85,2450,2111],{"class":152},[85,2452,2453,2455],{"class":144,"line":629},[85,2454,314],{"class":148},[85,2456,2457],{"class":169}," zero\n",[85,2459,2460],{"class":144,"line":635},[85,2461,277],{"class":169},[85,2463,2464],{"class":144,"line":656},[85,2465,160],{"emptyLinePlaceholder":159},[85,2467,2468],{"class":144,"line":665},[85,2469,465],{"class":220},[85,2471,2472],{"class":144,"line":676},[85,2473,1264],{"class":220},[85,2475,2476,2478,2480,2482,2484,2486,2488,2490,2492,2494,2496,2498,2500,2502,2504,2506,2508,2510,2512],{"class":144,"line":702},[85,2477,294],{"class":148},[85,2479,377],{"class":169},[85,2481,381],{"class":380},[85,2483,303],{"class":148},[85,2485,306],{"class":152},[85,2487,248],{"class":169},[85,2489,2145],{"class":152},[85,2491,402],{"class":169},[85,2493,2092],{"class":152},[85,2495,2329],{"class":169},[85,2497,483],{"class":152},[85,2499,334],{"class":169},[85,2501,396],{"class":380},[85,2503,2338],{"class":152},[85,2505,492],{"class":169},[85,2507,2092],{"class":152},[85,2509,402],{"class":169},[85,2511,500],{"class":148},[85,2513,503],{"class":169},[85,2515,2516,2518,2520],{"class":144,"line":707},[85,2517,417],{"class":169},[85,2519,420],{"class":152},[85,2521,423],{"class":169},[85,2523,2524,2526,2528,2530],{"class":144,"line":712},[85,2525,429],{"class":148},[85,2527,432],{"class":169},[85,2529,435],{"class":152},[85,2531,423],{"class":169},[85,2533,2534,2536,2538],{"class":144,"line":722},[85,2535,1323],{"class":169},[85,2537,534],{"class":148},[85,2539,537],{"class":169},[85,2541,2542,2544,2546],{"class":144,"line":734},[85,2543,799],{"class":148},[85,2545,1334],{"class":148},[85,2547,1337],{"class":169},[85,2549,2550,2552,2554,2556,2558,2561],{"class":144,"line":739},[85,2551,1342],{"class":148},[85,2553,2428],{"class":152},[85,2555,248],{"class":169},[85,2557,2092],{"class":152},[85,2559,2560],{"class":169},"](), ",[85,2562,1350],{"class":779},[85,2564,2565],{"class":144,"line":745},[85,2566,353],{"class":169},[85,2568,2569],{"class":144,"line":765},[85,2570,1359],{"class":220},[85,2572,2573,2575,2577,2579,2581,2583],{"class":144,"line":785},[85,2574,799],{"class":148},[85,2576,1366],{"class":169},[85,2578,1369],{"class":152},[85,2580,1372],{"class":169},[85,2582,1234],{"class":152},[85,2584,1377],{"class":169},[85,2586,2587],{"class":144,"line":790},[85,2588,1382],{"class":220},[85,2590,2591,2593],{"class":144,"line":796},[85,2592,1387],{"class":152},[85,2594,616],{"class":169},[85,2596,2597,2599,2601,2603,2605,2607],{"class":144,"line":819},[85,2598,1342],{"class":148},[85,2600,2428],{"class":152},[85,2602,248],{"class":169},[85,2604,2092],{"class":152},[85,2606,2560],{"class":169},[85,2608,1350],{"class":779},[85,2610,2611],{"class":144,"line":836},[85,2612,353],{"class":169},[85,2614,2615,2617,2619],{"class":144,"line":841},[85,2616,314],{"class":148},[85,2618,1410],{"class":169},[85,2620,1413],{"class":779},[85,2622,2623],{"class":144,"line":846},[85,2624,277],{"class":169},[85,2626,2627],{"class":144,"line":852},[85,2628,160],{"emptyLinePlaceholder":159},[85,2630,2631],{"class":144,"line":865},[85,2632,561],{"class":220},[85,2634,2635,2637,2639,2641,2643,2645,2647,2649,2651,2653,2655,2657,2659,2661,2663],{"class":144,"line":870},[85,2636,294],{"class":148},[85,2638,377],{"class":169},[85,2640,381],{"class":380},[85,2642,303],{"class":148},[85,2644,306],{"class":152},[85,2646,248],{"class":169},[85,2648,2145],{"class":152},[85,2650,402],{"class":169},[85,2652,2092],{"class":152},[85,2654,2329],{"class":169},[85,2656,579],{"class":152},[85,2658,334],{"class":169},[85,2660,396],{"class":380},[85,2662,2338],{"class":152},[85,2664,503],{"class":169},[85,2666,2667,2669,2671],{"class":144,"line":876},[85,2668,417],{"class":169},[85,2670,420],{"class":152},[85,2672,423],{"class":169},[85,2674,2675,2677,2679,2681],{"class":144,"line":885},[85,2676,429],{"class":148},[85,2678,432],{"class":169},[85,2680,435],{"class":152},[85,2682,423],{"class":169},[85,2684,2685,2687],{"class":144,"line":890},[85,2686,613],{"class":152},[85,2688,616],{"class":169},[85,2690,2691],{"class":144,"line":905},[85,2692,277],{"class":169},[85,2694,2695],{"class":144,"line":1550},[85,2696,160],{"emptyLinePlaceholder":159},[85,2698,2699],{"class":144,"line":1555},[85,2700,632],{"class":220},[85,2702,2703,2705,2707,2709,2711,2713,2715,2717,2719,2721,2723,2725],{"class":144,"line":1564},[85,2704,294],{"class":148},[85,2706,377],{"class":169},[85,2708,381],{"class":380},[85,2710,303],{"class":148},[85,2712,306],{"class":152},[85,2714,248],{"class":169},[85,2716,2145],{"class":152},[85,2718,402],{"class":169},[85,2720,2092],{"class":152},[85,2722,2329],{"class":169},[85,2724,650],{"class":152},[85,2726,653],{"class":169},[85,2728,2729,2731,2733],{"class":144,"line":1575},[85,2730,417],{"class":169},[85,2732,420],{"class":152},[85,2734,423],{"class":169},[85,2736,2737,2739,2741,2743],{"class":144,"line":1580},[85,2738,429],{"class":148},[85,2740,432],{"class":169},[85,2742,435],{"class":152},[85,2744,423],{"class":169},[85,2746,2747,2749,2751,2753,2755,2757,2759,2761,2763,2765,2767,2769],{"class":144,"line":1586},[85,2748,679],{"class":169},[85,2750,446],{"class":148},[85,2752,684],{"class":152},[85,2754,334],{"class":169},[85,2756,245],{"class":148},[85,2758,248],{"class":169},[85,2760,2145],{"class":152},[85,2762,253],{"class":169},[85,2764,926],{"class":152},[85,2766,248],{"class":169},[85,2768,2092],{"class":152},[85,2770,2771],{"class":169},"])\n",[85,2773,2774],{"class":144,"line":1613},[85,2775,277],{"class":169},[85,2777,2778],{"class":144,"line":1639},[85,2779,160],{"emptyLinePlaceholder":159},[85,2781,2782,2784,2786],{"class":144,"line":1644},[85,2783,294],{"class":148},[85,2785,717],{"class":152},[85,2787,653],{"class":169},[85,2789,2790,2792,2794,2796,2798,2800,2802,2805],{"class":144,"line":1649},[85,2791,725],{"class":169},[85,2793,534],{"class":148},[85,2795,297],{"class":152},[85,2797,248],{"class":169},[85,2799,87],{"class":148},[85,2801,402],{"class":169},[85,2803,2804],{"class":148},"int",[85,2806,2807],{"class":169},"]()\n",[85,2809,2810],{"class":144,"line":1668},[85,2811,160],{"emptyLinePlaceholder":159},[85,2813,2814],{"class":144,"line":1682},[85,2815,1583],{"class":220},[85,2817,2818,2820,2822,2824,2827,2829,2832,2834,2836,2838],{"class":144,"line":1687},[85,2819,748],{"class":169},[85,2821,391],{"class":152},[85,2823,334],{"class":169},[85,2825,2826],{"class":176},"\"height\"",[85,2828,402],{"class":169},[85,2830,2831],{"class":779},"175",[85,2833,402],{"class":169},[85,2835,1605],{"class":779},[85,2837,303],{"class":148},[85,2839,1610],{"class":169},[85,2841,2842,2844,2846,2848,2850,2852,2854,2856,2858,2860],{"class":144,"line":1692},[85,2843,748],{"class":169},[85,2845,391],{"class":152},[85,2847,334],{"class":169},[85,2849,1622],{"class":176},[85,2851,402],{"class":169},[85,2853,1627],{"class":779},[85,2855,402],{"class":169},[85,2857,1632],{"class":779},[85,2859,303],{"class":148},[85,2861,1610],{"class":169},[85,2863,2864],{"class":144,"line":1698},[85,2865,160],{"emptyLinePlaceholder":159},[85,2867,2868],{"class":144,"line":1716},[85,2869,793],{"class":220},[85,2871,2872,2874,2876,2878,2880,2882,2884,2886],{"class":144,"line":1721},[85,2873,799],{"class":148},[85,2875,802],{"class":169},[85,2877,534],{"class":148},[85,2879,807],{"class":169},[85,2881,483],{"class":152},[85,2883,334],{"class":169},[85,2885,2826],{"class":176},[85,2887,816],{"class":169},[85,2889,2890,2892,2894,2896,2899],{"class":144,"line":1727},[85,2891,822],{"class":169},[85,2893,825],{"class":152},[85,2895,334],{"class":169},[85,2897,2898],{"class":176},"\"Value for height:\"",[85,2900,833],{"class":169},[85,2902,2903],{"class":144,"line":1753},[85,2904,353],{"class":169},[85,2906,2907],{"class":144,"line":1767},[85,2908,160],{"emptyLinePlaceholder":159},[85,2910,2911],{"class":144,"line":1772},[85,2912,1695],{"class":220},[85,2914,2915,2917,2919,2921,2923,2925],{"class":144,"line":1777},[85,2916,893],{"class":169},[85,2918,896],{"class":152},[85,2920,334],{"class":169},[85,2922,1707],{"class":779},[85,2924,1710],{"class":148},[85,2926,1713],{"class":169},[85,2928,2929],{"class":144,"line":1783},[85,2930,160],{"emptyLinePlaceholder":159},[85,2932,2933],{"class":144,"line":1802},[85,2934,1724],{"class":220},[85,2936,2937,2939,2941,2943,2945,2947,2949,2951,2953,2955],{"class":144,"line":1816},[85,2938,799],{"class":148},[85,2940,1732],{"class":169},[85,2942,534],{"class":148},[85,2944,807],{"class":169},[85,2946,483],{"class":152},[85,2948,334],{"class":169},[85,2950,2826],{"class":176},[85,2952,1745],{"class":169},[85,2954,1748],{"class":148},[85,2956,1337],{"class":169},[85,2958,2959,2961,2963,2965,2968],{"class":144,"line":1821},[85,2960,822],{"class":169},[85,2962,825],{"class":152},[85,2964,334],{"class":169},[85,2966,2967],{"class":176},"\"height key has expired\"",[85,2969,209],{"class":169},[85,2971,2972],{"class":144,"line":1826},[85,2973,353],{"class":169},[85,2975,2976],{"class":144,"line":1831},[85,2977,160],{"emptyLinePlaceholder":159},[85,2979,2980],{"class":144,"line":1846},[85,2981,1780],{"class":220},[85,2983,2984,2986,2988,2990,2992,2994,2996,2998],{"class":144,"line":1851},[85,2985,799],{"class":148},[85,2987,802],{"class":169},[85,2989,534],{"class":148},[85,2991,807],{"class":169},[85,2993,483],{"class":152},[85,2995,334],{"class":169},[85,2997,1622],{"class":176},[85,2999,816],{"class":169},[85,3001,3002,3004,3006,3008,3010],{"class":144,"line":1856},[85,3003,822],{"class":169},[85,3005,825],{"class":152},[85,3007,334],{"class":169},[85,3009,1811],{"class":176},[85,3011,833],{"class":169},[85,3013,3014],{"class":144,"line":1879},[85,3015,353],{"class":169},[85,3017,3018],{"class":144,"line":1893},[85,3019,160],{"emptyLinePlaceholder":159},[85,3021,3022],{"class":144,"line":1898},[85,3023,1695],{"class":220},[85,3025,3026,3028,3030,3032,3034,3036],{"class":144,"line":1903},[85,3027,893],{"class":169},[85,3029,896],{"class":152},[85,3031,334],{"class":169},[85,3033,1707],{"class":779},[85,3035,1710],{"class":148},[85,3037,1713],{"class":169},[85,3039,3040],{"class":144,"line":1908},[85,3041,160],{"emptyLinePlaceholder":159},[85,3043,3044],{"class":144,"line":1933},[85,3045,1724],{"class":220},[85,3047,3048,3050,3052,3054,3056,3058,3060,3062,3064,3066],{"class":144,"line":1946},[85,3049,799],{"class":148},[85,3051,1732],{"class":169},[85,3053,534],{"class":148},[85,3055,807],{"class":169},[85,3057,483],{"class":152},[85,3059,334],{"class":169},[85,3061,1622],{"class":176},[85,3063,1745],{"class":169},[85,3065,1748],{"class":148},[85,3067,1337],{"class":169},[85,3069,3070,3072,3074,3076,3078],{"class":144,"line":1951},[85,3071,822],{"class":169},[85,3073,825],{"class":152},[85,3075,334],{"class":169},[85,3077,1888],{"class":176},[85,3079,209],{"class":169},[85,3081,3082],{"class":144,"line":1956},[85,3083,353],{"class":169},[85,3085,3086],{"class":144,"line":1965},[85,3087,160],{"emptyLinePlaceholder":159},[85,3089,3090],{"class":144,"line":1970},[85,3091,849],{"class":220},[85,3093,3094,3096,3098,3100,3102,3104,3107,3109,3111,3113],{"class":144,"line":1981},[85,3095,748],{"class":169},[85,3097,391],{"class":152},[85,3099,334],{"class":169},[85,3101,1917],{"class":176},[85,3103,402],{"class":169},[85,3105,3106],{"class":779},"1",[85,3108,402],{"class":169},[85,3110,1605],{"class":779},[85,3112,303],{"class":148},[85,3114,1610],{"class":169},[85,3116,3118,3120,3122,3124,3126],{"class":144,"line":3117},114,[85,3119,748],{"class":169},[85,3121,579],{"class":152},[85,3123,334],{"class":169},[85,3125,1917],{"class":176},[85,3127,209],{"class":169},[85,3129,3131],{"class":144,"line":3130},115,[85,3132,160],{"emptyLinePlaceholder":159},[85,3134,3136],{"class":144,"line":3135},116,[85,3137,873],{"class":220},[85,3139,3141,3143,3145],{"class":144,"line":3140},117,[85,3142,748],{"class":169},[85,3144,650],{"class":152},[85,3146,423],{"class":169},[85,3148,3150],{"class":144,"line":3149},118,[85,3151,160],{"emptyLinePlaceholder":159},[85,3153,3155,3157,3159,3161],{"class":144,"line":3154},119,[85,3156,893],{"class":169},[85,3158,896],{"class":152},[85,3160,899],{"class":169},[85,3162,902],{"class":220},[85,3164,3166],{"class":144,"line":3165},120,[85,3167,277],{"class":169},[11,3169,3170,3171,3173,3174,3178],{},"Awesome! Congrats on building a generic in-memory cache. You can start using this in your Go applications. One thing to note here - we are removing keys during ",[69,3172,100],{}," calls. There can be cases - where your key is expired but is still consuming memory in your map. To solve for this, you can run a ",[3175,3176,3177],"em",{},"regular interval goroutine"," that checks for expired keys and removes them from your cache. I'll leave this as an exercise for you all. Feel free to reach out in case you're stuck or want to share implementation.",[56,3180,3181,3183,3187,3215,3219,3242,3259,3268,3270,3273,3282],{},[59,3182],{},[20,3184,3186],{"id":3185},"resources","Resources",[93,3188,3189,3195,3201,3208],{},[96,3190,3191],{},[48,3192,3194],{"href":50,"rel":3193},[52],"Popular Package for in-memory cache in go",[96,3196,3197],{},[48,3198,3200],{"href":75,"rel":3199},[52],"Introduction to Generics",[96,3202,3203],{},[48,3204,3207],{"href":3205,"rel":3206},"https:\u002F\u002Fwww.mohitkhare.com\u002Fblog\u002Fgo-with-redis\u002F",[52],"Using Redis as cache in Go",[96,3209,3210],{},[48,3211,3214],{"href":3212,"rel":3213},"https:\u002F\u002Fawesome-go.com\u002Fcaches\u002F",[52],"Open source cache implementations",[80,3216,3218],{"id":3217},"books-to-learn-golang","Books to learn Golang",[93,3220,3221,3228,3235],{},[96,3222,3223],{},[48,3224,3227],{"href":3225,"rel":3226},"https:\u002F\u002Famzn.to\u002F3fYLCqz",[52],"Go Programming Language",[96,3229,3230],{},[48,3231,3234],{"href":3232,"rel":3233},"https:\u002F\u002Famzn.to\u002F3s7fWS3",[52],"Learning Go",[96,3236,3237],{},[48,3238,3241],{"href":3239,"rel":3240},"https:\u002F\u002Famzn.to\u002F3t6PM37",[52],"Go in Action",[42,3243,3244],{},[11,3245,3246,3247,3252,3253,3258],{},"Do explore articles on ",[48,3248,3251],{"href":3249,"rel":3250},"https:\u002F\u002Fwww.mohitkhare.com\u002Fcategories\u002Fgolang",[52],"Golang"," and ",[48,3254,3257],{"href":3255,"rel":3256},"https:\u002F\u002Fwww.mohitkhare.com\u002Fcategories\u002Fsystem%20design",[52],"System Design",". You'll learn something new 💡",[11,3260,3261,3262,3267],{},"Liked the article? Consider ",[48,3263,3266],{"href":3264,"rel":3265},"https:\u002F\u002Fwww.buymeacoffee.com\u002FchHAzigTb",[52],"supporting me"," ☕️",[59,3269],{},[11,3271,3272],{},"I hope you learned something new. Feel free to suggest improvements ✔️",[11,3274,3275,3276,3281],{},"Follow me on ",[48,3277,3280],{"href":3278,"rel":3279},"https:\u002F\u002Ftwitter.com\u002Fmkfeuhrer",[52],"Twitter"," for updates and resources. Let's connect!",[11,3283,3284],{},[15,3285,3286],{},"Keep exploring 🔎 Keep learning 🚀",[3288,3289,3290],"style",{},"html pre.shiki code .szBVR, html code.shiki .szBVR{--shiki-default:#D73A49;--shiki-dark:#F97583}html pre.shiki code .sScJk, html code.shiki .sScJk{--shiki-default:#6F42C1;--shiki-dark:#B392F0}html pre.shiki code .sVt8B, html code.shiki .sVt8B{--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .sZZnC, html code.shiki .sZZnC{--shiki-default:#032F62;--shiki-dark:#9ECBFF}html pre.shiki code .sJ8bj, html code.shiki .sJ8bj{--shiki-default:#6A737D;--shiki-dark:#6A737D}html pre.shiki code .s4XuR, html code.shiki .s4XuR{--shiki-default:#E36209;--shiki-dark:#FFAB70}html pre.shiki code .sj4cs, html code.shiki .sj4cs{--shiki-default:#005CC5;--shiki-dark:#79B8FF}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}",{"title":139,"searchDepth":156,"depth":156,"links":3292},[3293,3294],{"id":22,"depth":156,"text":23},{"id":63,"depth":156,"text":64,"children":3295},[3296,3298,3299],{"id":82,"depth":163,"text":3297},"Using mapstringinterface",{"id":919,"depth":163,"text":920},{"id":1991,"depth":163,"text":1992},[3251,3301],"Programming","Learn about in-memory caching in Golang, it's benefits and how to implement it with and without generics with a TTL(expiry).",false,"md","blog\u002Fgo-in-memory-cache\u002Fgo-in-memory-cache-card.webp","in memory cache golang, implement cache golang, local cache go, ttl cache golang, cache go generics",{},"go-in-memory-cache","\u002Fblog\u002Fgo-in-memory-cache",{"title":5,"description":3302},"blog\u002Fgo-in-memory-cache","2024-03-28","JWmdxZHMsgGyWdDP4CV1b4LmOZVK1CqtKxLUC6tSaxo",[3315,3322,3328,3336,3345,3351,3358,3365,3371,3377,3383,3389,3395,3405,3411,3418,3425,3432,3438,3445,3451,3457,3463,3469,3475,3477,3483,3489,3496,3503,3509,3515,3521,3527,3533,3539,3545,3551,3557,3563,3569,3575,3581,3588,3594,3600,3606,3613,3619,3625,3632,3639,3645,3652,3658,3665,3671,3678,3684,3690,3696,3702,3708,3714,3720,3726,3732,3738,3744,3750,3757,3763,3770,3776,3782,3788,3795,3801],{"path":3316,"title":3317,"description":3318,"categories":3319,"draft":159,"year":3321,"series":6},"\u002Fblog\u002Fai-assisted-workstation","Building an AI-Assisted Personal Workstation","How I built a personal AI workstation: markdown knowledge base, portable agent skills, handoff-driven sessions. What worked, what broke, what I would change.",[3320,3301],"Productivity","2026-08-26",{"path":3323,"title":3324,"description":3325,"categories":3326,"draft":3303,"year":3327,"series":6},"\u002Fblog\u002Faws-s3-golang","Uploading images to AWS S3 in Golang","In this tutorial I cover how to upload, fetch and manage other operations for objects on AWS S3 in Golang",[3251,3301],"2020-01-12",{"path":3329,"title":3330,"description":3331,"categories":3332,"draft":3303,"year":3335,"series":6},"\u002Fblog\u002Fbooks-for-engineers","Best Books for Software Engineers","Best Books to help you build you software engineering career - ranging from fundamentats, interview prep to productivity.",[3333,3334],"Books","Life","2021-12-26",{"path":3337,"title":3338,"description":3339,"categories":3340,"draft":3303,"year":3344,"series":6},"\u002Fblog\u002Fbuilding-acrons","Building Acrons 🚀","Building Acrons, a one-stop tool to decode everyday acronyms like DIY, FOMO, and BRB without losing your flow.",[3341,3342,3343],"Side Projects","Web","Tools","2020-05-26",{"path":3346,"title":3347,"description":3348,"categories":3349,"draft":3303,"year":3350,"series":6},"\u002Fblog\u002Fcap-theorem","CAP Theorem Explained","Learn the concept and misconceptions around popular CAP theorem in system design.",[3257,3301],"2021-07-26",{"path":3352,"title":3353,"description":3354,"categories":3355,"draft":3303,"year":3357,"series":6},"\u002Fblog\u002Fcode-reviews","Code Review Checklist","Why code reviews matter, and best practices that catch bugs early and keep code quality high before merge.",[3356],"Engineering Principles","2020-07-20",{"path":3359,"title":3360,"description":3361,"categories":3362,"draft":3303,"year":3364,"series":6},"\u002Fblog\u002Fdark-mode","Add Dark mode to websites","Dark mode is ❤️️ Add it to your websites with little CSS and JS",[3363,3342],"Javascript","2020-07-04",{"path":3366,"title":3367,"description":3368,"categories":3369,"draft":3303,"year":3370,"series":6},"\u002Fblog\u002Fdate-time-golang","Working with Date and Time in Go","Learn how to use time in Golang - Multiple formats, locations and using date.",[3251,3301],"2020-10-09",{"path":3372,"title":3373,"description":3374,"categories":3375,"draft":3303,"year":3376,"series":6},"\u002Fblog\u002Fdefer-in-golang","Understanding Defer In Golang","Learn about defer keyword in golang and how it can help you avoid panics due to bugs.",[3251,3301],"2021-05-05",{"path":3378,"title":3379,"description":3380,"categories":3381,"draft":3303,"year":3382,"series":6},"\u002Fblog\u002Fenums-golang","Implementing Enums in Golang","Enums are a way to defined set of constant values. Learn how to implement enums in Go using iota with examples.",[3251,3301],"2021-12-18",{"path":3384,"title":3385,"description":3386,"categories":3387,"draft":3303,"year":3388,"series":6},"\u002Fblog\u002Fenvironment-variable-golang","Guide to Environment variables in Go","Learn what are environment variables and how to use them in Go",[3251,3301],"2020-08-14",{"path":3390,"title":3391,"description":3392,"categories":3393,"draft":3303,"year":3394,"series":6},"\u002Fblog\u002Ferror-handling-golang","Handle errors the right way — Golang","How to handle errors in golang to make your life easy",[3251,3301],"2020-01-30",{"path":3396,"title":3397,"description":3398,"categories":3399,"draft":159,"year":3402,"series":3403},"\u002Fblog\u002Ffile-attack-document-macros","File Attack Deep Dives, Part 3: Document Macros","How malicious VBA hides in vbaProject.bin, which AutoOpen entry points fire it, and the sandbox signals that catch it.",[3400,3401],"Security","Systems","2026-09-17",{"name":3404,"part":163},"File Attack Deep Dives",{"path":3406,"title":3407,"description":3408,"categories":3409,"draft":3303,"year":3321,"series":3410},"\u002Fblog\u002Ffile-attack-field-guide","How File-Based Attacks Land: A Detection Engineer's Field Guide","A practical taxonomy of how malware and phishing arrive as files, why classic controls miss them, and how detection should think.",[3400,3401],{"name":3404,"part":145},{"path":3412,"title":3413,"description":3414,"categories":3415,"draft":159,"year":3416,"series":3417},"\u002Fblog\u002Ffile-attack-html-smuggling","File Attack Deep Dives, Part 2: HTML Smuggling","How attackers assemble malware inside the browser with Blob URLs, and the URL and script tells that catch it.",[3400,3401],"2026-09-10",{"name":3404,"part":156},{"path":3419,"title":3420,"description":3421,"categories":3422,"draft":159,"year":3423,"series":3424},"\u002Fblog\u002Ffile-attack-lnk-iso","File Attack Deep Dives, Part 5: LNK and ISO Smuggling","How ISO containers and weaponized shortcuts bypass Mark of the Web, and the forensic fields that catch them.",[3400,3401],"2026-10-01",{"name":3404,"part":186},{"path":3426,"title":3427,"description":3428,"categories":3429,"draft":159,"year":3430,"series":3431},"\u002Fblog\u002Ffile-attack-pdf-url-actions","File Attack Deep Dives, Part 4: PDF URL Actions","How PDF OpenAction, Launch, and URI actions turn opening a document into a phishing click, and the action audit that catches them.",[3400,3401],"2026-09-24",{"name":3404,"part":173},{"path":3433,"title":3434,"description":3435,"categories":3436,"draft":3303,"year":3437,"series":6},"\u002Fblog\u002Ffile-upload-golang","Uploading Files in Golang with Multipart Request","Learn how to upload files from your client to server as a multipart request in Golang.",[3251,3301],"2021-03-13",{"path":3439,"title":3440,"description":3441,"categories":3442,"draft":3303,"year":3444,"series":6},"\u002Fblog\u002Fgit-branch","Git Branch 101","Branching is a new path of development that makes it a lot easier to build features. Learn why and how to use branching in git.",[3443,3301],"Git","2022-03-20",{"path":3446,"title":3447,"description":3448,"categories":3449,"draft":3303,"year":3450,"series":6},"\u002Fblog\u002Fgit-pull-request-template","Guide to Pull Request Templates","Improve collaboration and code reviews with pull request templates. Blog include PR template and how to create one on github\u002Fgitlab",[3443,3301],"2023-08-24",{"path":3452,"title":3453,"description":3454,"categories":3455,"draft":3303,"year":3456,"series":6},"\u002Fblog\u002Fgit-remove-sensitive-info","Securing Git: Remove Sensitive Information","Protect your code from security breaches by using BFG tool to remove sensitive information from Git history. Learn how to do it in this comprehensive guide.",[3443,3301],"2023-10-16",{"path":3458,"title":3459,"description":3460,"categories":3461,"draft":3303,"year":3462,"series":6},"\u002Fblog\u002Fgit-tags-explained","Git tags : Explained","What Git tags are, why and when to use them, and how to start tagging releases in your own projects.",[3443,3301],"2020-06-18",{"path":3464,"title":3465,"description":3466,"categories":3467,"draft":3303,"year":3468,"series":6},"\u002Fblog\u002Fgo-dependency-injection","Dependency Injection in Go using Wire","Learn about dependency injection, its benefits and how to implement it in Go services using wire",[3251,3301],"2022-11-26",{"path":3470,"title":3471,"description":3472,"categories":3473,"draft":3303,"year":3474,"series":6},"\u002Fblog\u002Fgo-generics","Introduction to Generics in Go","Learn about generics in Golang, it's benefits and how to implement it in applications.",[3251,3301],"2022-11-27",{"path":3309,"title":5,"description":3302,"categories":3476,"draft":3303,"year":3312,"series":6},[3251,3301],{"path":3478,"title":3479,"description":3480,"categories":3481,"draft":3303,"year":3482,"series":6},"\u002Fblog\u002Fgo-makefile","Ultimate Makefile for Golang","Boost your productivity and save time with ultimate Makefile for Golang projects.",[3251,3301],"2024-06-10",{"path":3484,"title":3485,"description":3486,"categories":3487,"draft":3303,"year":3488,"series":6},"\u002Fblog\u002Fgo-middleware","Mastering Middlewares in Golang","Learn about middlewares, their use cases and how to implement them in Golang applications",[3251,3301],"2022-03-13",{"path":3490,"title":3491,"description":3492,"categories":3493,"draft":3303,"year":3495,"series":6},"\u002Fblog\u002Fgo-naming-conventions","Naming Conventions in Golang","Why naming conventions matter in Go, with best practices and practical examples for clear, readable, maintainable code.",[3251,3301,3494],"Code Quality","2023-05-19",{"path":3497,"title":3498,"description":3499,"categories":3500,"draft":3303,"year":3502,"series":6},"\u002Fblog\u002Fgo-with-redis","Go with Redis","A practical introduction to using Redis with Golang to make your applications faster with in-memory data storage.",[3251,3501,3301],"Database","2020-05-03",{"path":3504,"title":3505,"description":3506,"categories":3507,"draft":3303,"year":3508,"series":6},"\u002Fblog\u002Fgolang-maps","Learn Maps in Golang (with examples)","A complete guide to maps in Golang: creating maps, adding and removing items, iterating, and how map equality works.",[3251,3301],"2020-09-10",{"path":3510,"title":3511,"description":3512,"categories":3513,"draft":3303,"year":3514,"series":6},"\u002Fblog\u002Fguide-to-cdn","Guide to Content Delivery Network","CDN is one of the backbone of modern world internet infrastructure. Learn about Content Delivery Network, it's working, types and benefits.",[3257,3301],"2022-01-23",{"path":3516,"title":3517,"description":3518,"categories":3519,"draft":3303,"year":3520,"series":6},"\u002Fblog\u002Fguide-to-rule-engines","Guide to Rule Engines","Rule Engines help in solving changing business requirements with ease. Learn all about Rule engines, it's working, benefits and how to implement one in Golang",[3251,3301],"2022-09-12",{"path":3522,"title":3523,"description":3524,"categories":3525,"draft":3303,"year":3526,"series":6},"\u002Fblog\u002Fhexagonal-architecture","Guide to Hexagonal Architecture","Learn how to design efficient application with hexagonal architecture with practical example",[3257,3301],"2020-12-13",{"path":3528,"title":3529,"description":3530,"categories":3531,"draft":3303,"year":3532,"series":6},"\u002Fblog\u002Fhttp-status-codes","Learn HTTP Status Codes","A tour of HTTP response status codes, what each class means, and when to use which code in your applications.",[3342,3301],"2020-07-30",{"path":3534,"title":3535,"description":3536,"categories":3537,"draft":3303,"year":3538,"series":6},"\u002Fblog\u002Fintroduction-to-goroutines","Introduction to Goroutines","Understand the basics of concurrency and learn how to work with Goroutines in golang.",[3251,3301],"2021-04-10",{"path":3540,"title":3541,"description":3542,"categories":3543,"draft":3303,"year":3544,"series":6},"\u002Fblog\u002Fjson-in-postgres-with-golang","Storing JSON in Postgres with Golang","Learn how to store JSON objects in Postgres and how to implement it in Golang.",[3301,3501,3251],"2021-02-13",{"path":3546,"title":3547,"description":3548,"categories":3549,"draft":3303,"year":3550,"series":6},"\u002Fblog\u002Fjson-web-token","Complete Guide to JWT","JSON Web Tokens are a very compact way to carry information. Learn about JWTs in depth, from its structure to when to use it.",[3301,3342],"2021-11-20",{"path":3552,"title":3553,"description":3554,"categories":3555,"draft":3303,"year":3556,"series":6},"\u002Fblog\u002Flearn-to-say-no","Learning to say No","Learn why it's important to say 'NO'. How it helps in increasing productivity and explore strategies for saying No",[3334,3333],"2022-04-09",{"path":3558,"title":3559,"description":3560,"categories":3561,"draft":3303,"year":3562,"series":6},"\u002Fblog\u002Flearn-unlearn-relearn","Learn - Unlearn - Relearn","Unlearning things to learn new is the way to grow. Discover how to do that!",[3320,3334],"2020-09-25",{"path":3564,"title":3565,"description":3566,"categories":3567,"draft":3303,"year":3568,"series":6},"\u002Fblog\u002Flinting-in-golang","Introduction to Linting in Go","Introduction to improving code quality using linting. Learn how to add linting in your Go projects.",[3251,3301],"2021-07-07",{"path":3570,"title":3571,"description":3572,"categories":3573,"draft":3303,"year":3574,"series":6},"\u002Fblog\u002Fload-balancing","Load Balancing 101","Complete guide on load balancers explaining the internal working and how does it help in making applications efficient.",[3257,3301],"2021-05-29",{"path":3576,"title":3577,"description":3578,"categories":3579,"draft":3303,"year":3580,"series":6},"\u002Fblog\u002Fmaking-decisions-the-right-way","Making Decisions: The right way","Decisions are hard! Learn how to make the right decisions always",[3320,3334],"2020-06-07",{"path":3582,"title":3583,"description":3584,"categories":3585,"draft":3303,"year":3587,"series":6},"\u002Fblog\u002Fmanage-logs-with-logrotate","Using Logrotate to manage logs","Learn how to use logrotate system utility to manage logs with example",[3586,3301],"Linux","2020-09-08",{"path":3589,"title":3590,"description":3591,"categories":3592,"draft":3303,"year":3593,"series":6},"\u002Fblog\u002Fmarshal-structs-golang","Marshal structs the right way: Golang","Why Golang marshals empty structs into your JSON instead of null, and how to marshal structs the right way.",[3251,3301],"2020-03-31",{"path":3595,"title":3596,"description":3597,"categories":3598,"draft":3303,"year":3599,"series":6},"\u002Fblog\u002Fnotes-almanack-naval","Book Notes : Almanack of Naval Ravikant","My notes\u002Fhighlights from Almanack of Naval Ravikant book by Eric Jorgenson",[3333,3334],"2020-10-17",{"path":3601,"title":3602,"description":3603,"categories":3604,"draft":3303,"year":3605,"series":6},"\u002Fblog\u002Fnotes-anything-you-want","Book Notes : Anything you want","My notes\u002Fhighlights from Anything you want book by Derek Sivers",[3333,3334],"2021-09-25",{"path":3607,"title":3608,"description":3609,"categories":3610,"draft":3303,"year":3612,"series":6},"\u002Fblog\u002Fnotes-getting-real","Book Notes : Getting Real","My notes and highlights from Getting Real by Jason Fried and David Heinemeier Hansson on building web applications.",[3333,3611],"Startups","2020-11-03",{"path":3614,"title":3615,"description":3616,"categories":3617,"draft":3303,"year":3618,"series":6},"\u002Fblog\u002Fnotes-hell-yeah-or-no","Book Notes : Hell Yeah or No","My notes\u002Fhighlights from Hell Yeah or No book by Derek Sivers",[3333,3334],"2020-09-16",{"path":3620,"title":3621,"description":3622,"categories":3623,"draft":3303,"year":3624,"series":6},"\u002Fblog\u002Fnotes-how-to-be-a-capitalist","Book Notes : How to Be a Capitalist Without Any Capital","My notes\u002Fhighlights from How to Be a Capitalist Without Any Capital by Nathan Latka",[3333,3611],"2020-01-07",{"path":3626,"title":3627,"description":3628,"categories":3629,"draft":3303,"year":3631,"series":6},"\u002Fblog\u002Fnotes-lean-b2b","Book Notes : Lean B2B","My notes and highlights from Lean B2B by Étienne Garbugli on assessing markets, building MVPs, and selling to businesses.",[3333,3630],"Entrepreneurship","2022-07-02",{"path":3633,"title":3634,"description":3635,"categories":3636,"draft":3303,"year":3638,"series":6},"\u002Fblog\u002Fnotes-lets-talk-money","Book Notes : Let's Talk Money","My notes and highlights from Let's Talk Money by Monica Halan on managing personal finances and savings.",[3333,3637],"Personal Finance","2021-02-26",{"path":3640,"title":3641,"description":3642,"categories":3643,"draft":3303,"year":3644,"series":6},"\u002Fblog\u002Fnotes-obviously-awesome","Book Notes : Obviously Awesome","My notes and highlights from Obviously Awesome by April Dunford on product positioning and marketing strategy.",[3333,3611],"2020-04-26",{"path":3646,"title":3647,"description":3648,"categories":3649,"draft":3303,"year":3651,"series":6},"\u002Fblog\u002Fnotes-refactoring-ui","Book Notes: Refactoring UI","My notes and highlights from Refactoring UI by Adam Wathan and Steve Schoger, full of practical design tips for engineers.",[3333,3650],"Design","2020-05-09",{"path":3653,"title":3654,"description":3655,"categories":3656,"draft":3303,"year":3657,"series":6},"\u002Fblog\u002Fnotes-rework","Book Notes: Rework","My notes and highlights from Rework by Jason Fried and David Heinemeier Hansson on a better way to succeed in business.",[3333,3611],"2021-04-14",{"path":3659,"title":3660,"description":3661,"categories":3662,"draft":3303,"year":3664,"series":6},"\u002Fblog\u002Fone-on-one-meetings","Guide to Effective 1:1 Meetings","One on One meetings are important for your personal & professional growth. Learn how to master 1:1s with your manager and peers.",[3663,3320],"Career","2023-03-05",{"path":3666,"title":3667,"description":3668,"categories":3669,"draft":3303,"year":3670,"series":6},"\u002Fblog\u002Fpersonal-okrs","Personal OKRs for Success","Why one should set personal OKRs and how to achieve success with them",[3320,3334],"2020-06-27",{"path":3672,"title":3673,"description":3674,"categories":3675,"draft":3303,"year":3677,"series":6},"\u002Fblog\u002Fpoker-tips","Poker Tips: Johns Hopkins Poker Class","Notes from Johns Hopkins poker course. This guide will help you improve in Poker and win some large pots.",[3334,3676],"Poker","2020-06-13",{"path":3679,"title":3680,"description":3681,"categories":3682,"draft":3303,"year":3683,"series":6},"\u002Fblog\u002Fpomodoro","Get work done: The Pomo Way","Learn to focus and get productive by following the Pomodoro Technique",[3320],"2020-10-24",{"path":3685,"title":3686,"description":3687,"categories":3688,"draft":3303,"year":3689,"series":6},"\u002Fblog\u002Fpostgres-constraints","Postgres Constraints","Constraints are line of defense for database. Explore various types of constrainsts in postgres",[3501,3301],"2020-11-07",{"path":3691,"title":3692,"description":3693,"categories":3694,"draft":3303,"year":3695,"series":6},"\u002Fblog\u002Fppf-explained","PPF Explained","Learn basics about Public Provident Fund and why you should invest",[3334,3637],"2020-12-24",{"path":3697,"title":3698,"description":3699,"categories":3700,"draft":3303,"year":3701,"series":6},"\u002Fblog\u002Fproductivity-chrome-extensions","Boost Productivity with Chrome Extensions","Utitizing chrome extensions to boost your productivity!",[3320,3343,3342],"2020-04-24",{"path":3703,"title":3704,"description":3705,"categories":3706,"draft":3303,"year":3707,"series":6},"\u002Fblog\u002Fproductivity-in-vscode","Improve your productivity with VS Code","Key VS Code features like the integrated terminal, shortcuts, and extensions that improved my everyday productivity.",[3320,3301],"2020-03-12",{"path":3709,"title":3710,"description":3711,"categories":3712,"draft":3303,"year":3713,"series":6},"\u002Fblog\u002Freading-101","Improving Reading 101","Why reading matters, how to build a reading habit, and what to read next - from my own journey into books.",[3333,3334],"2020-04-04",{"path":3715,"title":3716,"description":3717,"categories":3718,"draft":3303,"year":3719,"series":6},"\u002Fblog\u002Freverse-proxy","Understanding Reverse Proxy","Learn about reverse proxy, how it is different from forward proxy and explore advantages of using it in system design.",[3257,3301],"2021-10-03",{"path":3721,"title":3722,"description":3723,"categories":3724,"draft":3303,"year":3725,"series":6},"\u002Fblog\u002Frunning-periodic-background-task-golang","Running periodic background tasks in Golang","How to run periodic background tasks in Golang by combining cron-style scheduling with background execution.",[3251,3301],"2019-11-21",{"path":3727,"title":3728,"description":3729,"categories":3730,"draft":3303,"year":3731,"series":6},"\u002Fblog\u002Fsessions-in-golang","Sessions using Golang and Redis","How cookies and sessions work, and how to implement persistent login sessions in Golang using Redis.",[3251,3501,3301],"2020-02-25",{"path":3733,"title":3734,"description":3735,"categories":3736,"draft":3303,"year":3737,"series":6},"\u002Fblog\u002Fsolid-dry-kiss-yagni","Solid Dry Kiss Yagni","An introduction to the SOLID, DRY, KISS, and YAGNI principles and how they help you write cleaner, robust code.",[3356],"2020-07-17",{"path":3739,"title":3740,"description":3741,"categories":3742,"draft":3303,"year":3743,"series":6},"\u002Fblog\u002Fstack-in-golang","Implement Stack in Golang","Learn how to implement stack data structure in Golang (Full code)",[3251,3301],"2020-09-14",{"path":3745,"title":3746,"description":3747,"categories":3748,"draft":3303,"year":3749,"series":6},"\u002Fblog\u002Fstart-oss-today","Start your Open Source journey today","Start your OSS journey with intro to GIT. Participate in Hacktoberfest!",[3443,3301],"2020-09-19",{"path":3751,"title":3752,"description":3753,"categories":3754,"draft":3303,"year":3756,"series":6},"\u002Fblog\u002Fsticky-social-bar","Sticky social share component in HTML","Learn how to build a social media sharing component in HTML and add it to your website.",[3301,3755],"Frontend","2021-02-05",{"path":3758,"title":3759,"description":3760,"categories":3761,"draft":3303,"year":3762,"series":6},"\u002Fblog\u002Fterm-insurance","Term insurance Simplified","Everything you need to know before you buy a term insurance.",[3334,3637],"2020-11-29",{"path":3764,"title":3765,"description":3766,"categories":3767,"draft":3303,"year":3769,"series":6},"\u002Fblog\u002Fterminal-output-with-redirection","Handling terminal outputs with Redirection","Learn how to handle terminal outputs with Redirection and saving it to files",[3586,3768,3301],"Terminal","2020-09-06",{"path":3771,"title":3772,"description":3773,"categories":3774,"draft":3303,"year":3775,"series":6},"\u002Fblog\u002Fthink-and-grow-rich","Book Notes: Think and Grow Rich","My notes and highlights from Think and Grow Rich by Napoleon Hill, covering its process for building wealth.",[3333,3334],"2020-05-19",{"path":3777,"title":3778,"description":3779,"categories":3780,"draft":3303,"year":3781,"series":6},"\u002Fblog\u002Ftransactions-postgres-golang","Transactions on Postgres with Golang","Performing Postgres database operations in Golang with GORM, from basic queries to full transaction support.",[3251,3501,3301],"2020-03-18",{"path":3783,"title":3784,"description":3785,"categories":3786,"draft":3303,"year":3787,"series":6},"\u002Fblog\u002Fwaitgroups-in-golang","WaitGroups in Golang","Learn about WaitGroups in golang and how to use them to perform concurrent operations without blocking the main thread.",[3251,3301],"2022-05-31",{"path":3789,"title":3790,"description":3791,"categories":3792,"draft":3303,"year":3794,"series":6},"\u002Fblog\u002Fwhat-i-use","What I Use: Products and Softwares","List of what I use in my day to day life ranging from terminal, editors, softwares, devices to accessories",[3334,3793],"Tech","2024-06-01",{"path":3796,"title":3797,"description":3798,"categories":3799,"draft":3303,"year":3800,"series":6},"\u002Fblog\u002Fyear-in-review-2020","Year in Review: 2020","It's a wrap! 2020 was a crazy year, See how my year went!",[3334],"2020-12-31",{"path":3802,"title":3803,"description":3804,"categories":3805,"draft":3303,"year":3806,"series":6},"\u002Fblog\u002Fyear-in-review-2021","Year in Review: 2021","It's a wrap! 2021 was a mixed bag, full of ups and downs. Key Goal for 2022: Start now!",[3334],"2021-12-31",1788773187207]