What is a cache in memory? I could not find much information about this from the Internet.
Actually I was asked to create a cache in memory based on the concept of OO using C ++, but I just don’t know how to start. Any suggestions would be appreciated.
It depends on the context, but, as a rule, the cache stores a certain value in memory, so it can be restored later, instead of creating a new object. This is most often used in combination with databases - or indeed in any application where building / extracting an object is expensive.
( , !):
class Integer { int value; public: Integer(int value) : value(value) { sleep(1000); // Simulates an expensive constructor } };
, :
Integer one(1); Integer two(2); // etc.
... ( ), , 2:
Integer two(2);
. , ? , , factory :
class Integer { int value; static std::map<int, Integer> cache; Integer(int value) : value(value) { sleep(1000); // Simulates an expensive constructor } friend Integer make_int(int); }; Integer make_int(int value) { std::map<int, Integer>::iterator i = Integer::cache.find(value); if (i != Integer::cache.end()) return i->second; Integer ret = Integer(value); Integer::cache[value] = ret; return ret; }
make_int . :
make_int
Integer one = make_int(1); Integer two = make_int(2); Integer other = make_int(2); // Recycles instance from above.
, , , , HTTP- . , LRU. , , , , , , . , , .
, "" . , , , . , , , . , (, DAO), .
memcached ++ API , :
, , , - .Memcached is a key-value in memory to store small pieces of arbitrary data (rows, objects) from the results of database calls, API calls, or a rendering page.
, , , - .
Memcached is a key-value in memory to store small pieces of arbitrary data (rows, objects) from the results of database calls, API calls, or a rendering page.
Source: https://habr.com/ru/post/1796109/More articles:Good books for interpreter and compiler using C ++? - c ++Working with MS Integer8 / LargeInteger in Java? - javahttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1796106/swt-combolist-only-allows-to-add-item-value-but-no-key&usg=ALkJrhi7mHRXohmss5Ot5Vj3FQzor5ufYgScala Option collection method does not like my PartialFunction - scalaLimit Delphi 7 pgm corporate LAN - delphiEBNF / parboiled: how to convert regexp to PEG? - javaRedirect stdout and stderr in windows service - redirectКак вы находите индекс элемента в унаследованном классе Collection? - inheritanceWhy use a display: built-in unit? - htmlAsync thread queue java.lang.UnsupportedOperationException exception handling - androidAll Articles