{"action":"created","issue":{"url":"https://api.github.com/repos/orientechnologies/orientdb/issues/6204","repository_url":"https://api.github.com/repos/orientechnologies/orientdb","labels_url":"https://api.github.com/repos/orientechnologies/orientdb/issues/6204/labels{/name}","comments_url":"https://api.github.com/repos/orientechnologies/orientdb/issues/6204/comments","events_url":"https://api.github.com/repos/orientechnologies/orientdb/issues/6204/events","html_url":"https://github.com/orientechnologies/orientdb/issues/6204","id":156512916,"number":6204,"title":"Caching and referenced records","user":{"login":"kerner1000","id":13817521,"avatar_url":"https://avatars.githubusercontent.com/u/13817521?v=3","gravatar_id":"","url":"https://api.github.com/users/kerner1000","html_url":"https://github.com/kerner1000","followers_url":"https://api.github.com/users/kerner1000/followers","following_url":"https://api.github.com/users/kerner1000/following{/other_user}","gists_url":"https://api.github.com/users/kerner1000/gists{/gist_id}","starred_url":"https://api.github.com/users/kerner1000/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kerner1000/subscriptions","organizations_url":"https://api.github.com/users/kerner1000/orgs","repos_url":"https://api.github.com/users/kerner1000/repos","events_url":"https://api.github.com/users/kerner1000/events{/privacy}","received_events_url":"https://api.github.com/users/kerner1000/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/orientechnologies/orientdb/labels/storage%20team","name":"storage team","color":"c5def5"}],"state":"open","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/orientechnologies/orientdb/milestones/64","html_url":"https://github.com/orientechnologies/orientdb/milestones/2.1.x%20(next%20hotfix)","labels_url":"https://api.github.com/repos/orientechnologies/orientdb/milestones/64/labels","id":1282180,"number":64,"title":"2.1.x (next hotfix)","description":"","creator":{"login":"lvca","id":312606,"avatar_url":"https://avatars.githubusercontent.com/u/312606?v=3","gravatar_id":"","url":"https://api.github.com/users/lvca","html_url":"https://github.com/lvca","followers_url":"https://api.github.com/users/lvca/followers","following_url":"https://api.github.com/users/lvca/following{/other_user}","gists_url":"https://api.github.com/users/lvca/gists{/gist_id}","starred_url":"https://api.github.com/users/lvca/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lvca/subscriptions","organizations_url":"https://api.github.com/users/lvca/orgs","repos_url":"https://api.github.com/users/lvca/repos","events_url":"https://api.github.com/users/lvca/events{/privacy}","received_events_url":"https://api.github.com/users/lvca/received_events","type":"User","site_admin":false},"open_issues":154,"closed_issues":27,"state":"open","created_at":"2015-08-31T15:18:49Z","updated_at":"2016-05-24T14:28:23Z","due_on":"2016-05-23T22:00:00Z","closed_at":null},"comments":2,"created_at":"2016-05-24T13:51:11Z","updated_at":"2016-05-24T15:02:15Z","closed_at":null,"body":"Hi,\r\n\r\nI experience some difficulties with the caching mechanism.\r\n\r\nI have a document db and documents store references to other documents.\r\n\r\nIf I modify these references without altering the document itself, I can only see these changes after clearing the db's cache.\r\n\r\n`db.getLocalCache().clear()`\r\n\r\nsee [#6080](https://github.com/orientechnologies/orientdb/issues/6080).\r\n\r\nHow can I trigger a reload of documents that contain modified references without invalidating the whole cache?\r\n\r\nMany thanks!\r\n"},"comment":{"url":"https://api.github.com/repos/orientechnologies/orientdb/issues/comments/221299928","html_url":"https://github.com/orientechnologies/orientdb/issues/6204#issuecomment-221299928","issue_url":"https://api.github.com/repos/orientechnologies/orientdb/issues/6204","id":221299928,"user":{"login":"kerner1000","id":13817521,"avatar_url":"https://avatars.githubusercontent.com/u/13817521?v=3","gravatar_id":"","url":"https://api.github.com/users/kerner1000","html_url":"https://github.com/kerner1000","followers_url":"https://api.github.com/users/kerner1000/followers","following_url":"https://api.github.com/users/kerner1000/following{/other_user}","gists_url":"https://api.github.com/users/kerner1000/gists{/gist_id}","starred_url":"https://api.github.com/users/kerner1000/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kerner1000/subscriptions","organizations_url":"https://api.github.com/users/kerner1000/orgs","repos_url":"https://api.github.com/users/kerner1000/repos","events_url":"https://api.github.com/users/kerner1000/events{/privacy}","received_events_url":"https://api.github.com/users/kerner1000/received_events","type":"User","site_admin":false},"created_at":"2016-05-24T15:02:15Z","updated_at":"2016-05-24T15:02:15Z","body":"I have DocumentA and DocumentB\r\n\r\nA has a one2ManyRelationship to B\r\nB has a many2OneRelationship to A\r\n\r\nWhen I load more data into the db, I update A but not B.\r\n\r\nWhen I display the db in my application, I query for B, which holds a reference to A.\r\n\r\nIf B contains a reference to any A, I display A, if not, I display B.\r\n\r\nReferences are stored as Document IDs, so I assume the document with this ID is not checked for changes as well but just loaded from the cache.\r\n\r\n`public static void establishOne2ManyRelationship(ODocument documentFirst, String classNameFirst, String fieldNameFirst, ODocument documentSecond, String classNameSecond, String fieldNameSecond) {\r\n\r\n\t\t// left side\r\n\t\taddToReferenceCollection(documentFirst, classNameFirst, fieldNameFirst, documentSecond);\r\n\t\t// right side\r\n\t\tsetReference(documentSecond, classNameSecond, fieldNameSecond, documentFirst);\r\n\t}`\r\n\r\n`public static void establishMany2OneRelationship(ODocument documentFirst, String classNameFirst, String fieldNameFirst, ODocument documentSecond, String classNameSecond, String fieldNameSecond) {\r\n\r\n\t\t// left side\r\n\t\tsetReference(documentFirst, classNameFirst, fieldNameFirst, documentSecond);\r\n\t\t// right side\r\n\t\taddToReferenceCollection(documentSecond, classNameSecond, fieldNameSecond, documentFirst);\r\n\t}`\r\n\r\n`private static void addToReferenceCollection(ODocument document, String className, String fieldName, ODocument value) {\r\n\r\n\t\tif(isValid(document, className)) {\r\n\t\t\tCollection<ODocument> refCollection = new HashSet<>(getReferenceCollection(document, className, fieldName));\r\n\t\t\trefCollection.add(value);\r\n\t\t\tsetReferenceCollection(document, className, fieldName, refCollection);\r\n\t\t} else\r\n\t\t\tthrow new IllegalArgumentException(\"For \" + document);\r\n\t}`\r\n\r\n`public static Collection<ODocument> getReferenceCollection(ODocument document, String className, String fieldName) {\r\n\r\n\t\tif(isValid(document, className)) {\r\n\t\t\ttry {\r\n\t\t\t\tCollection<OIdentifiable> id = document.field(fieldName, OType.LINKSET);\r\n\t\t\t\tif(id == null) {\r\n\t\t\t\t\treturn Collections.emptySet();\r\n\t\t\t\t}\r\n\t\t\t\tCollection<ODocument> result = new HashSet<>();\r\n\t\t\t\tfor(OIdentifiable i : id) {\r\n\t\t\t\t\tif(i != null) {\r\n\t\t\t\t\t\tODocument r = i.getRecord();\r\n\t\t\t\t\t\tif(r != null)\r\n\t\t\t\t\t\t\tresult.add(r);\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\treturn result;\r\n\t\t\t} catch(Exception e) {\r\n\t\t\t\tlogger.error(e.getLocalizedMessage(), e);\r\n\t\t\t\treturn Collections.emptySet();\r\n\t\t\t}\r\n\t\t}\r\n\t\tthrow new IllegalArgumentException(\"For \" + document);\r\n\t}`\r\n\r\n`private static void setReferenceCollection(ODocument document, String className, String fieldName, Collection<ODocument> value) {\r\n\r\n\t\tif(isValid(document, className)) {\r\n\t\t\tdocument = save(document.field(fieldName, value, OType.LINKSET));\r\n\t\t} else\r\n\t\t\tthrow new IllegalArgumentException(\"For \" + document);\r\n\t}`"}}
{"actor":{"display_login":"kerner1000"}}