TTLの問題または正確で高速なキャッシングのための戦略の回避

TTL («time to live» — ) . TTL . ? - , ? ? .






, . , , , . — .





, — . . « » (: , ), Memcache PHP- (: , apache2, ).



, , ( ), PHP , , .





. TTL .





1:

- . . CSV- upload #42345 . HTML- markdown. , , , , "". .





TTL. .





, Memcache Redis (. ), LRU (least recently used). («») , («») . «» . , «» .





( «») . ( ), «» . .





, , , , .





( ) ( TTL). . : TTL , .





2:

, . , : , , . . , , .





— , . , , - TTL , - . 





, . – : , ( ).





, , .





3:

. : User user_id, email_address. , . , . .





, , . , - , , . , , , .





, , . , , , : , , .





, — . , : , . .





4:

, , , « ».





: , . , .





:





/namespaces/user657



, № 657 , , 1514937600.





, , :





  • /user657/1514937600/likes/article-12312







  • /user657/1514937600/comments/article-12315







  • /user657/1514937600/something-else-completely







: , . - , , , , . .





: . . -, , . , . , , . , , .





: «» , . «» , , :





1.   , , . «», . , LRU .





2.   , . , .





5: HTTP — PUSH PURGE

HTTP , TTL. 1 : TTL, CDN , .





4 HTTP, , « ». , URL- -, JavaScript.





CDN API , , . CDN , , , , - fly.io, CDN, .





-, , Varnish Apache Traffic Server, PUSH PURGE, . , 2 3. , -?





HTTP , .





— . , , , .





, , , Baser Software .





, , , — . - -, -. , , , . « "", », — -. , , , , Memcache - . « ! !»





. Redis , : , , . Redis , — Redis.





Redis (maxmemory) . , — — - . , . (maxmemory-policy) , . , , . allkeys-lru.





, ElastiCache AWS, : volatile-lru. , TTL. «» , TTL. , volatile-lru — -, . -, , . -, , , , TTL.





Redis « » . , . Redis , , . Redis .





, . , , - , .





— - . , . 2, , - , .





, : 0 % . , .





API

Python . :





from functools import lru_cache

@lru_cache(maxsize=1000)
def get_slow_thing_v1(thing_id):
    thing = get_slow_thing_from_a_database_layer(thing_id)
    return thing
      
      



, 1: . /, :





from pyappcache import RedisCache

my_cache = RedisCache()

def get_slow_thing_v2(thing_id):
    thing = my_cache.get_by_str(thing_id)

    if thing is None:
        thing = get_slow_thing_from_a_database_layer()
        my_cache.set_by_str(thing_id, thing)

    return thing

def update_something_slow(thing_id, new_thing):
    set_thing_in_a_database_layer(new_thing)
    my_cache.set_by_str(thing_id, new_thing)
      
      



, -.





, — get_something_slow_v1. , . , , , .





Python , : pyappcache ( , ).





, :





  • Python;





  • PEP484, typecheck cache ;





  • Memcache, Redis Sqlite-as-a-cache;





  • , ;





  • .





Python, dogpile.cache, cachew , , Redis-py pylibmc .





, . , , , , , . « » , .





, AWS Memcache. , .





: . -: « , , , ». - , , . - , , , .





, — .





Apache (née Inktomi) Traffic Server PUSH PURGE.





, Varnish , .





, , ( , ) Memcache: Memcache , (Tinou), Memcache, (Joshua Thijssen). memcache , , , .





Redis LRU , . Redis, . , .





, :





  • Data Scientist





  • Data Analyst





  • Data Engineering









  • Fullstack- Python





  • Java-





  • QA- JAVA





  • Frontend-









  • C++





  • Unity





  • -





  • iOS-





  • Android-









  • Machine Learning





  • "Machine Learning Deep Learning"





  • " Data Science"





  • " Machine Learning Data Science" 





  • "Python -"





  • " "









  • DevOps








All Articles